In this practice class we will study the use of fork and execlp functions in a combination See

In this practice class, we will study the use of the fork() and execlp() functions in combination. See the skeleton code given here. - Skeleton C Program: fork + execlp #include #include int main (int argo, char *argv[]) { int pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf (stderr, "Fork Failed"); exit (-1); } else if (pid == 0) { /* child process */ execlp ("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit (0); } } Assignment: Q1. Write a C code for implementing fork + execlp combination where execlp is used in child to do the following: (A) starts a simple program printing "Hello World" on the screen, and then (B) uses the system() function to execute the "ps" command. The parent process uses the system() function to execute the "ls" command and then waits for the child to finish. Measure the total time to execute the program using the system clock.

In this practice class, we will study the use of the fork() and execlp() functions in combination. See the skeleton code given here.

– Skeleton C Program: fork + execlp

#include
#include

int main (int argo, char *argv[]) {
int pid; /* fork another process */
pid = fork();

if (pid < 0) { /* error occurred */ fprintf (stderr, "Fork Failed"); exit (-1); } else if (pid == 0) { /* child process */ execlp ("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit (0); } } Assignment: Q1. Write a C code for implementing fork + execlp combination where execlp is used in child to do the following: (A) starts a simple program printing "Hello World" on the screen, and then (B) uses the system() function to execute the "ps" command. The parent process uses the system() function to execute the "ls" command and then waits for the child to finish. Measure the total time to execute the program using the system clock.


 
Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.

 
Instant
Download

Student review: (2 ratings) 2 out of 2 people found this solution helpful.