linux - How to control execution of parent process after execl() call in C program? -



linux - How to control execution of parent process after execl() call in C program? -

i have simple c programme executes application using fork() , execl(). if execl() fails run application, have phone call function in parent process , exit kid process. if execl() runs application, have show success log parent process. so, parent process should wait child's execl() phone call (just call, not till end of execution of application), info status, , create decisions , go on own execution. here code.

int main() { int iexecretval, pid; pid = fork(); if (pid == -1) { } else if (pid > 0) { } else { iexecretval = execl("./flute-static", "./flute-static", "-send", "-a192.168.190.1/6666", "jflute.1.2.tar.gz", null); if (iexecretval == -1) { /*execl() failed, need error handling in parent process*/ } _exit(0); } /*parent's normal execution*/ } int handlesuccessfromparent() { /*should called when exec phone call successful*/ } int handlefailurefromparent() { /*should called when exec phone call not successful*/ }

we know execl() not homecoming on success. so, how phone call handlesuccessfromparent() , handlefailurefromparent() functions after execl() phone call in child. please help me.

the kid process needs exit error status (non-zero; 1 common, exit_failure standard c).

the parent process needs wait kid finish, , capture child's exit status, using wait() or waitpid().

if need know whether kid died don't want wait complete, utilize waitpid() wnohang after little pause allow kid seek , run (a sub-second delay long enough).

c linux exec fork child-process

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -