Problem with fork inside a thread and system()



Hi everybody,
I am experiencing an annoying problem with fork() and system()
In my program I need to launch the "pppd" from a thread, so, I create
a new process with fork and then in the child process I launch with
system the pppd to connect an embedded system to internet.
The problem is that pppd fails.
Here is my example code:

int my_thread(...)
{
pid=fork();
if (pid==EAGAIN || pid==ENOMEM)
{
abort();
}
switch(pid)
{
case 0: // child
{
system ("/usr/sbin/pppd call gprs");
printf("Error execv:%s",strerror(errno));
exit(0);
}
break;
case -1:
abort();
break;
default: // father
father stuff.....
}
}

in var/log/messages I can read:
daemon.notice pppd[2145]: pppd 2.4.3 started by root, uid 0 <----
this is O.K.
daemon.err pppd[2145]: Connect script failed <--- I can't believe
it!!!

On the other hand I made a simple program with a main and a simple
fork and system call and this is right and works fine!!!! I can't
believe it!!!!
Is there any difference between call system inside a child created
from a thread and a child created from a single main (wich is also a
thread).

Regards,
Unai.
.



Relevant Pages

  • Re: Problem with fork inside a thread and system()
    ... In my program I need to launch the "pppd" from a thread, so, I create ... a new process with fork and then in the child process I launch with ... father stuff..... ...
    (comp.os.linux.development.apps)
  • Re: timing a fork
    ... if ($kid) { ... What it does is say that the parent isn't interested in ... Once a parent process has forked it can carry on on its own while the child ... In fact what a call to 'system' does is to fork a child ...
    (perl.beginners)
  • Re: Ruby lacks atfork : The evil that lives in fork...
    ... so that there's no way to ensure mutex to share ... Give the resource to the child. ... fork() in a multi-threaded program. ... multi-threaded I/O libraries, which are almost sure to be invoked ...
    (comp.lang.ruby)
  • Re: EPERM from pthread_mutex_unlock after fork using pthread_atfork()
    ... So, if the fork() creates a copy of the parent, the child should get a copy of the mutex as well. ... it should be locked in the child process and the parent process once the forkprocessing is complete. ...
    (comp.programming.threads)
  • Re: [PATCH for -mm] getrusage: fill ru_maxrss value
    ... you say the BSD fork line is "fork: ... This struct is filled as a parameter to getrusage syscall. ... testcase1: fork inherit? ... fork child: self 103540 children 0 ...
    (Linux-Kernel)