gthread and fork/exec
- From: lingdanmiaoD netscape net
- To: orbit-list gnome org
- Subject: gthread and fork/exec
- Date: Thu, 10 Jan 2002 15:31:05 -0500
Hello,
I am trying to use gthread and fork/exec to have a thread and child
process. It seems both thread and child process cannot work properly,
namely, there is no new /tmp/testfile generated, and the thread may
not work sometime. It is the same when using g_spawn_ ...
Could somebody take a look?
Thanx a lot!
The following libs are used
glib-1.3.11
libpthread.so.0 => /lib/libpthread.so.0
libdl.so.2 => /lib/libdl.so.2
/lib/ld-linux.so.2 => /lib/ld-linux.so.2
######################################################
#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
static void *thread_function(void *arg)
{
int i;
for ( i=0; i<20; i++ ) {
g_message("In Thread: Iter i = %d\n", i);
}
return NULL;
}
int main(void)
{
GThread* new_thread;
if (!g_thread_supported()) g_thread_init (NULL);
new_thread = g_thread_create (thread_function, NULL, FALSE, NULL);
{
pid_t pid = fork();
if(pid == -1) {
g_message("fork error");
exit(-1);
}
else if(pid == 0) {
g_message ("in child process");
execlp("touch", "touch", "/tmp/testfile", NULL);
g_message("execlp error");
_exit(-1);
}
}
g_message("in Parent");
while(1);
exit(0);
}
####################################################
--
__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]