Question

M ALL ELEG220 LABS jamalbaraka X Race Condition in operating syst X o Mail- Jamal A Baraka Outlook nments.dk X Lauk.edu.kw/pl
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) Number of child processes created = 2n - 1 .

And total number of processes created is = Number of child processes + 1.

Explanation : -

On first call there will be one child process created by first fork.

On second call, there will be 2 child processes created by second fork.

On third call, there will be 4 child processes created by third fork

and so on.

So in total 24 = 16 processes are called.

2)Output will be :-

CHILD: 0 CHILD: -1 CHILD: -4 CHILD: -9 CHILD: -16

PARENT: 0 PARENT: 1 PARENT: 2 PARENT: 3 PARENT: 4

Explanation:-

When the fork() is called, it duplicates the process, so after calling fork there

are actually 2 instances of the program running.

To know which process is parent one and which is child process is:

in the parent process, the PID of the child process will return positive integer from the call of fork().

That's why the if (pid> 0 ) { /* PARENT */ } code works. In the child process, fork() just returns 0.

Add a comment
Know the answer?
Add Answer to:
M ALL ELEG220 LABS jamalbaraka X Race Condition in operating syst X o Mail- Jamal A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork...

    Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...

  • Operating Systems Questions (Please help if you can) 1. A computer has cache, main memory, and...

    Operating Systems Questions (Please help if you can) 1. A computer has cache, main memory, and a disk used for virtual memory. If a referenced word is in the cache, 20ns are required to access it. If it is in main memory but not in the cache, 60ns are required to load it into the cache (this includes the time to originally check the cache), and then, the reference is started again. If the word is not in main memory,...

  • GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h>...

    GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> // Function ptototypes int readX(); void writeX(int); int main() /// chi read x ---> divi ---> write x into file ---> par read x --> sub--> write x into file---> chi read x-->etc {    int pid;           // pid: used to keep track of the child process    int x = 19530;       // x: our value as integer   ...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT