Do it in LINUX ONLY The following program use redirect to implement env | grep H
ID: 3597273 • Letter: D
Question
Do it in LINUX ONLY
The following program use redirect to implement env | grep HOME, which prints out your home directory.
(a) Read the man page of dup2 and execl system calls.
(b) Fill in the blanks in the code provided and make sure it works as the description above.
(c) Compile the code and make sure it is executable.
(d) Upload your source code.
Thank You :)
#include #include #include nclude int main (void) t pid.t childpid int fd [2] ) setup a pipe/ perror (Failed to setup pipeline"; return 1; ) fork a child */ perror Failed to fork a child"); return 1; ) /env is the child */ if (dup2 (fd [1], perror("Failed to redirect stdout of env”); perrorailed to close extra pipe descriptors on env); execl ( close unused file descriptor/ else if else ) /ezecute env / perror ("Failed to exec env”); return 1; if (dup2 (fd [0], *grep is the parent else if ( else perror Failed to redirect stdin of grep") perror Failed to close extra pipe file descriptors on grep"); ); * execute "grep HOME" exec perror Failed to exec grep" return 1;Explanation / Answer
Answer to the above problem:(go through it and give ur feedback)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.