I'm launching a process with the instruction
execl("./softCopia","softCopia",NULL);
softCopia is just a dummy that writes integers in a file.
I would like to know how can i get the pid of this process?
I'm launching a process with the instruction
execl("./softCopia","softCopia",NULL);
softCopia is just a dummy that writes integers in a file.
I would like to know how can i get the pid of this process?
Since all of the Unix exec functions replace the running process with the new one, the PID of the exec'd process is the same PID it was before.
So you get the PID by using the
getpid()
call, before callingexecl
.Or, if you actually want to continue running your main program and launch a new program, you use
fork()
first. Thefork()
function returns a negative value for errors, 0 for the new, child process, and the PID of the child in the parent. So the parent can then use one of thewait
functions or just continue on its business until later.