Question: 2. (10 points) You are developing a program to implement the following filter ps-au 1 grep nk 78 , il lists the call that pur
2. (10 points) You are developing a program to implement the following filter ps-au 1 grep nk 78 , il lists the call that pur reports a snapshot of the current processes and with the option - processes belonging to all users who are currently in the system. The objective of your program o pipe this large amount of output to prep and supply it with a specific user name, in this is to search for So p filters the input data based on the string nk 78 and only proce belonging to user 'nk78" will be printed Consider the following snippet of code that aims to set up the above-described hiter. int pid[21) pipe (pfd); if (fork ( 0) close (pdf[0]); dup2 (pd[1], STDOUT_FILENO); close (pfd[1]); execlp ("s", "ps", "au", (char =) NULL); exit (EXIT_FAILURE); 14 Create child to execute grep / if (fork ( 0) close (pfd[]); dup2 (pdf [1], STDIN_FILENO); close(pdf[1]); execlp ("grep", "grep", "nk78", (char exit (EXIT_FAILURE); ) NULL); 2 / / close pipes in parent and wait for children to exit close (pfd[0]); close (pfd[1]); wait (NULL); wait (NULL); The pipel) call in Line 2 creates a pipe within the kernel and provides the process with two descr ors: the read descriptor, pfd[0], and the write descriptor, pfd[1]. The above, code, howe as a major design flaw that will prevent it from correctly implementing the desired filter. Find aw and provide the corrected code. 2. (10 points) You are developing a program to implement the following filter ps-au 1 grep nk 78 , il lists the call that pur reports a snapshot of the current processes and with the option - processes belonging to all users who are currently in the system. The objective of your program o pipe this large amount of output to prep and supply it with a specific user name, in this is to search for So p filters the input data based on the string nk 78 and only proce belonging to user 'nk78" will be printed Consider the following snippet of code that aims to set up the above-described hiter. int pid[21) pipe (pfd); if (fork ( 0) close (pdf[0]); dup2 (pd[1], STDOUT_FILENO); close (pfd[1]); execlp ("s", "ps", "au", (char =) NULL); exit (EXIT_FAILURE); 14 Create child to execute grep / if (fork ( 0) close (pfd[]); dup2 (pdf [1], STDIN_FILENO); close(pdf[1]); execlp ("grep", "grep", "nk78", (char exit (EXIT_FAILURE); ) NULL); 2 / / close pipes in parent and wait for children to exit close (pfd[0]); close (pfd[1]); wait (NULL); wait (NULL); The pipel) call in Line 2 creates a pipe within the kernel and provides the process with two descr ors: the read descriptor, pfd[0], and the write descriptor, pfd[1]. The above, code, howe as a major design flaw that will prevent it from correctly implementing the desired filter. Find aw and provide the corrected code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
