This very simple example of exec()
system call. Here, I am trying to call execlp()
twice. But, I am not getting excepted output. It shows output only f
execlp ()
replaces the process that called it by the process which was called.
From this link:
"The exec() family of functions replaces the current process image with a new process image."
To retain both the processes, use fork().
#include <stdio.h>
#include <unistd.h>
int main() {
int ret1,ret2;
pid_t chd;
chd=fork();
if(chd==0)
ret1 = execlp( "pwd", "pwd", (char *) 0);
else if(chd>0)
ret2 = execlp( "date", "date", (char *) 0);
return 0;
}
execlp()
replaces the current process image with a new process image.
It does not return (unless there was an error starting the new process).
Therefore the second execlp()
call is never reached.