Hi,
i want to write a little prog which executes another one using the execvp()
function. The executed program should be monitored and when it exits some
action should happen.
I wrote the following little code fragment which works very well so long
the executed prog does not fork into background, meaning that it exits its
parent process after forking.
So my question is:
Is there a way to trace the executed prog and/or to get the pid of the new
process if it forks into background?
If that can't be accomplished using plain c maybe it can be done using
the linux proc filesystem?
---<snip>---
pid_t childpid = fork();
switch( childpid ) {
case -1: /* fork failed */
perror("fork(main)");
exit( EXIT_FAILURE );
case 0: /* fork succeed - child process */
execvp( argv_prog[0], argv_prog );
// this point should never be reached
perror("execvp(main)");
exit( EXIT_FAILURE );
break;
default: /* fork succeed - parent process */
cout << "childprocess running" << endl;
// wait until child exits
int wait_result, status;
waitpid( childpid, &status, WUNTRACED );
cout << "childprocess exited" << endl;
exit( EXIT_SUCCESS );
break;
arginfo.rm_pidfile_flag,Quote:}
---<snap>---
-timo
--
| Timo Benk
| Germany
| Registered Linux User #186431
| Fax/Voicemail: +49/0180 505258732297