Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a problem in using system()

Status
Not open for further replies.

13sio

Technical User
May 21, 2003
141
MO
hello,

i'm writing a interface by gtk+2.0 (a c based language) in linux. it's a window and have some buttons inside. when click a button, the program will call another software by system() command. if i do so, the interface window will halt. i wanna call another software and the window works normally.

thank you for your helping.
 
You'll need to create a spawn a separate process (see fork) or create another thread of execution (pthreads) within your program to handle the system call without freezing the interface.
 
hi,

thx dlkfjdlkfjdlfkd.

running the following code under RedHat 8.0,

----------------
#include <pthread.h>
#include <stdio.h>

void cb(void)
{
printf(&quot;%s&quot;, &quot;hi&quot;);
}

int main (int argc, char *argv[])
{
pthread_t threads;
int rc;
rc = pthread_create(&threads, NULL, (void *)cb, NULL);
if (rc) {
printf(&quot;ERROR; return code from pthread_create() is %d\n&quot;, rc);
}
return 0;
}
----------------

there are statements as follows

/thread.o In function `main':
/thread.o(.text+0x3c): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
 
> /thread.o(.text+0x3c): undefined reference to `pthread_create'
You need to add the name of the library to the compilation command line
Say
Code:
gcc -o prog thread.c -lpthread

The #include in the source code is for the compiler, so it knows how to call the function correctly
The -lpthread on the command line is for the linker, so it can find the actual implementation of the function.

> rc = pthread_create(&threads, NULL, (void *)cb, NULL);
If you declare your cb function like this, then there is no need for the cast when you call pthread_create()
Code:
void *cb(void *p)
{
   printf(&quot;%s&quot;, &quot;hi&quot;);
   return NULL;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top