execl family of functions; execl execlp execle exect execv execvp all performs a similar function by starting another program. This new program overlays the existing program, so you can never return to the to original code unless the call to execl fails. http://siber.cankaya.edu.tr/OperatingSystems/cfiles/code21.c code21.c and http://siber.cankaya.edu.tr/OperatingSystems/cfiles/code22.c code22.c
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
main()
{
int pid;
if ((pid = fork()) == 0) {
execl("/bin/ls", "ls", "/", 0);
}
else {
wait(&pid);
printf("Exec finished\n");
}
}
#include <unistd.h>
#include <stdio.h>
int main()
{
printf("Running ps with execlp\n");
execlp("ps", "ps", "-ax", 0);
printf("Done.\n");
exit(0);
}