the code below in detail. What is going to be done? What is the order of Lines L1,L2,L3,L4 ouput on the screen? (echo is the command to write the parameter (ex: echo merhaba writes merhaba on screen) (Suppose that value_1 = 3, value_2=5, value_3=2) | int main(int argc, char *argv[] ){ | pid_t pid, w; | int status, tim; | srand((unsigned) getpid()); | if ( argc < 4 ) { L1| cerr << "Usage " << *argv << " value_1 value_2 value_3\n"; | return 1; | } | for (int i = 1; i < 4; ++i) | if ((pid = fork( )) == 0)
Trace the code below in detail. What is going to be done? What is the order of Lines L1,L2,L3,L4 ouput on the screen? (echo is the command to write the parameter (ex: echo merhaba writes merhaba on screen) (Suppose that value_1 = 3, value_2=5, value_3=2)
| int main(int argc, char *argv[] ){
| pid_t pid, w;
| int status, tim;
| srand((unsigned) getpid());
| if ( argc < 4 ) {
L1| cerr << "Usage " << *argv << " value_1 value_2 value_3\n";
| return 1;
| }
| for (int i = 1; i < 4; ++i)
| if ((pid = fork( )) == 0)
| {
| tim = int (rand() %5);
L2| execl("echo", "echo", tim, (char *) 0);
| alarm(tim);
| sleep(4);
L3| cout << “After ” << tim << “second return to child” << endl;
| }
| else
L4| cout << "Forked child " << pid << endl;
|
| while ((w=wait(&status)) && w != -1)
| cout << "Wait on PID: " << dec << w << " returns status of "
| << setw(4) << setfill('0') << hex
| << setiosflags(ios::uppercase) << status << endl;
| return 0;
| }
approaches (i.e. write the pseudo code for
![2.
Trace the code below in detail. What is going to be done? What is the order of Lines
L1,L2,L3,L4 ouput on the screen? (echo is the command to write the parameter (ex: echo merhaba
writes merhaba on screen) (Suppose that value_1 = 3, value_2=5, value_3=2)
int main(int argc, char *argv] ){
pid_t pid, w;
int status, tim;
srand((unsigned) getpid());
if ( argc < 4) {
cerr << "Usage " << *argv << " value_1 value_2 value_3\n";
return 1;
}
for (int i = 1; i < 4; ++i)
if ((pid = fork( )) == 0)
{
tim = int (rand() %5);
execl("echo", "echo", tim, (char *) 0);
alarm(tim);
sleep(4);
cout << "After " << tim << “second return to child" << endl;
}
else
L1|
L2|
L3|
L4|
cout << "Forked child " << pid << endl;
while ((w=wait(&status)) && w != -1)
cout << "Wait on PID: " << dec << w <
<< setw(4) << setfill('0') << hex
< setiosflags(ios::uppercase) << status << endl;
returns status of "
return 0;
}
approaches (i.e. write the pseudo code for algorithms) for solving this new
problem...Discuss the details. Not just give names (!) or just the formulas. Discuss all necessary
details with the Pros/Cons...](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa3ba23ed-c7f0-46ae-8248-c092f69c266f%2F366e334b-6e32-4315-8a99-2964acace89d%2Fs3aeucr_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)