how does exec() do it? on successful call of exec() family of functions, they never return...
how to i emulate that.
assume the standard example,
now this would never return.
i m trying to emulate exec()'s never to return feature...
i m not trying anything fancy...only to emulate the "no return" feature once a command is executed.
void myexec(const char* path,const char* argv)
sleep(2); //make process orphan
exit(100); //exit to init
int main(int argc,char *argv)
printf("USAGE:%s <path> <command>\n",argv);
if( fork() == 0)
sleep(1); //suspend parent
exit(0); //be a bad parent ;)
printf("this should never be executed");
so when i run this program
[c_d@localhost cfiles]$ gcc 1.c
[c_d@localhost cfiles]$ ./a.out /bin/ls ls
1.c a.out fcopy.c~ frevread.c~ msg~ prgm1.c~ prgm2.c~ prgm3.c~ prgm4.c~ prgm5.c~ prgm7.c sth~
1.c~ cfiles.tar.7z file1~ key.c prgm1 prgm2 prgm3 prgm4 prgm5 prgm6.c prgm7.c~
alpha.c~ f1~ fread.c~ key.c~ prgm1.c prgm2.c prgm3.c prgm4.c prgm5.c prgm6.c~ printip.c~
[c_d@localhost cfiles]$ ./a.out /home/c_d/workspace/unix/shellscripts/ ./leapyear_prgm07.sh
2009 is not a leap year
i get what i want...the line "this should never be executed" never gets printed
but i m not happy...i m unnecessarily wasting away 2 secs for emulating this...
and i personally dont feel it as an elegant way to emulate exec()....
please help me grasp the internals of exec() call... and explain to me how it works and tell me if there is an alternative to make a function-call never return...
also please explain to me, why in execl*() a set of arguments is preferred to be passed as in
when it could have been implemented as
execl ("/bin/ls", "ls", "-l", (char *)0);
execl ("/bin/ls", "ls -l", (char *)0);
...and i have same complaint with execv*() style exec()...