I am running an external program with the command execvp, now I want to catch the exit code of the external program and if possible get the PID of it.
Is there anyway possible?(I know I can read $? in ubuntu and use ps faxu but these are dirty ways for that)
The
exec*functions does not return when the program has successfully run, so you can’t get the return code viaexecvp. However, if you usefork/wait, you could get the exit code from the status code in thewait*functions:You could check the example of in the man page of wait(2).