#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main(void)
{
pid_t child_pid;
int count = 6;
child_pid = fork();
if (child_pid == 0) {
execl("/bin/ls", "ls", "-l", NULL);
++count;
exit(1);
}
else
count = count * 2;
printf ("The counter = %d \n", count);
return 0;}
If execl succeeds, what will be the output for the child process? For the parent process?
If execl fails, what will be the output for the child process? For the parent process?
If execl succeeds
For the child process:- Print output of the command ls -l when execute in current directory through terminal. excel() returns only if there is error.
For parent process:- The counter = 12
Here counter value is 12 as it gets multipled by 2 and is initialized to 6;
If execl fails
For the child process:- No output. execl() returns -1 on error. It increments count variable and exits.
For parent process:- The counter = 12
Parent ouput is same as before as execl() is not invoked by parent.
Get Answers For Free
Most questions answered within 1 hours.