Question

What is the functionality of the following code? #include #include mainO <stdio.h> <unistd.h> int i,j; j-0: printf (Ready to fork.n) i-fork; if 0) this code.\n); printf The child executes for (i-0; i?5; i++) printf(Child j-dn.j); else j-vaito printf(The parent executes this code. Ln printf (Parent j-dn,j);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER

GIVEN BY

fork() process create a new child process for the recent process, which shares the matching resources as by the current method(parent process).

when fork() is called, if the go back value is 0, it means child process was effectively created.

wait() process makes the up to date process to wait (does'nt allow to advance to execute code) untill existing child route exits.

In this case,

i = 0

j = 0

i = fork()

if child process was formed productively, we print j value which is 5

Untill child finish its execution, process is set aside on hold (if we dont use wait its kinda multithreading then) and then route id of child is returned and assign to j (j = pid of childprocess).

Overall the plan is a demo of fork() and wait().

Add a comment
Know the answer?
Add Answer to:
What is the functionality of the following code? #include #include mainO <stdio.h> <unistd.h> int i,j; j-0:...
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
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