in reply to How do I get the process ID from a system("x &") call?

You don't, directly.

Consider what you've done. You've asked a shell to fork a process, and then exit itself. The shell certainly knew the child's PID, but you didn't ask the shell to tell you.

So, you'll either have to scruff through the process table yourself (hard), ask the shell to tell you before it exits (easier), or simply do the forking yourself (easiest, and most efficient).

Read up on fork for details. I'm sure I have a column or two on that as well.

-- Randal L. Schwartz, Perl hacker

  • Comment on •Re: How do I get the process ID from a system("x &") call?