Re: Problem with fork inside a thread and system()



CMorgan <uestebanez@xxxxxxxxx> writes:
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.....
}
}

Independently (but maybe related to) of your problem: system already
forks & waits for you, meaning there is no reason to call system from
a forked processes, except insofar this means the process calling
system isn't halted until the command has exited. If you don't want
the latter, don't use system,



.



Relevant Pages

  • Problem with fork inside a thread and system()
    ... 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 ... case 0: // child ...
    (comp.os.linux.development.apps)
  • Re: Problem with fork inside a thread and execv()
    ... I am experiencing an annoying problem with fork() and execv. ... In my program I need to launch the "pppd" from a thread, so, I create ...     return 0; ...
    (comp.lang.c)
  • 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 withforkand then in the child process I launch with ... Ok I Have tryed with execv: ...
    (comp.os.linux.development.apps)