PDA

View Full Version : Returning PID from execve family of functions?



ruairi
03-12-2003, 06:18 AM
Hi all,

Just wondering if it's possible to programatically get the PID of an app that has just been executed
using one of the execve(2) family of functions?

For context, I'm writing an app that will execute an application specified on the command line,
retrieve it's process id, and monitor various parameters over time, producing a graph.

While I am writing this on Linux, it has to be portable so GNU/BSD extensions to ANSI C aren't
any use to me unfortunately.

Any ideas at all would be appreciated, I have the feeling I'm missing something simple :-/

TIA,

Ruairi

Stewdent
03-12-2003, 06:24 AM
are you using fork to spawn a child process which then uses one of the execve(2) family of functions?

If so upon successful completion, fork() and fork1() return 0 to
the child process and return the process ID of the child
process to the parent process.

Hope that helps

ruairi
03-12-2003, 08:47 AM
Thanks for the reply :) 'Twas just what I needed.