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



On 28 dic, 16:55, CMorgan <uesteba...@xxxxxxxxx> wrote:
On 28 dic, 16:36, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:



CMorgan <uesteba...@xxxxxxxxx> writes:
I am experiencing an annoying problem withfork() andsystem()
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
systemthepppdto connect an embeddedsystemto internet.
The problem is thatpppdfails.
Here is my example code:

int my_thread(...)
{
pid=fork();
if (pid==EAGAIN || pid==ENOMEM)
{
abort();
}
switch(pid)
{
case 0: // child
{
system("/usr/sbin/pppdcall 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:systemalready
forks & waits for you, meaning there is no reason to callsystemfrom
a forked processes, except insofar this means the process callingsystemisn't halted until the command has exited. If you don't want
the latter, don't usesystem,

Ok I Have tryed with execv:
I just change the exec line for this one:
execv("/usr/sbin",macapi_gprs_ref->cmd_argv);

explanation:
"macapi_gprs_ref->cmd_argv" stores the parameters. I dumped it to my
log to check if parameters are right, and they are right.
Values of argv are:
parameter 0 = /usr/sbin/pppd
parameter 1 = call
parameter 2 = gprs

the result of execv is wrong:
"Error execv:Permission denied"

This is confusing, any hint?
Thanks

OK, I have advanced a little bit,
latest problem was due to an error in spanish translatin of execv man
page!!!
firs parameter of execv is not the path to the command but also the
complete path and file.
Anyway, now the script is launched but it fails
In var log messages I can read:
.... pppd 2.4.3 started by root, uid 0
.... Connect script failed

And the strangest thing is that from my easy program (only a main and
a fork) it works!!!!
any idea?
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 withforkand then in the child process I launch with ... father stuff..... ... Ok I Have tryed with execv: ...
    (comp.os.linux.development.apps)
  • 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 ... father stuff..... ... Ok I Have tryed with execv: ...
    (comp.os.linux.development.apps)
  • 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 ... father stuff..... ... Ok I Have tryed with execv: ...
    (comp.os.linux.development.apps)
  • Re: A question about multithreading
    ... launch ONE child process in one thread, ... total processor usage of a single process group (or whatever Win32 calls ... several processes simultaneously (IIRC recent versions of cmd support ...
    (comp.lang.perl.misc)
  • Re: how to run multiple processes from a single process?
    ... I am porting a win32 c++ program on Linux which first reads a list of ... I tried to achieve this using fork() and execv() API calls. ... launch program error occurs. ...
    (comp.os.linux.development.apps)