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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 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…

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...
Transcribed Image Text: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...
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education