7/ a/ what does int pid = fork() do? b/ after fork(); HOW TO TELL whether it\'s
ID: 3586364 • Letter: 7
Question
7/
a/ what does int pid = fork() do?
b/ after fork(); HOW TO TELL whether it's the parent or the child executing?
c/ What does int wait(int *status) do?
d/ What does int r = execve("a.out", argv, env); do?
e/ How does the system find a.out?__________________________________
f/ Assume the Linux cat is in /bin directory. When running YOUR sh with cat file1 file2 file3 > outfile How did YOU do the > outfile part?
g/ Draw a diagram to show exactly what's YOUR myargv in the r = execve("/bin/cat", myargv, env) call?_________________________
h/ What's the value of r? ____________ HOW would you do PIPE in cat file | grep pattern ?__________________________
Explanation / Answer
=>Answering the first 4 sub parts as per chegg's terms
a.) fork creates a new child process and returns the process id of the child process to the parent process.
b.) After fork, if pid > 0 then it is the parent process executing and if pid = 0 then it is the child process executing.
c.) The wait system call makes the parent wait unitl all its child processes has terminated. This call will suspend the parent process until its child processes terminates, at which time the wait() call returns and the parent process can continue.
d.)The execve() system call function is used to execute a binary executable or a script.The function returns nothing on success and -1 on error.
e.g
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.