zakzebrowski gives a partial answer above, and a bit more background might help you understand how to take it from there.
On *nix systems, when you call system() with a single argument, something magic happens under the covers. To handle shell meta-characters, system() invokes a shell, and the shell processes the argument. This muddies the waters. You clearly don't want the shell's process id, but it's gotten in the way. To get the process id of x, you need a finer grain of control, which can be had by an explicit fork()/exec().
After a fork() the parent process gets the process id of the child. The exec() replaces the child copy of the parent process, reusing the process id. There are a couple of things you need to watch out for. One is that if the exec() fails, the parent still thinks it has a valid process id. You can communicate this back to your parent process by a number of means, including an exit() code.
In reply to Re: How do I get the process ID from a system("x &") call?
by dws
in thread How do I get the process ID from a system("x &") call?
by zakzebrowski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |