How many processes are created
The client does not know for sure how long the message is, so it allocates a buffer bigger than it needs to be. The Problem: The problem arises if the server executes step 3 before the client has had a chance to execute step 2, which can easily happen depending on process scheduling.
In this case, when the client finally gets around to executing step 2, it will read in not only the original greeting, but also the first part of the work packet. This actually isn't even a problem at this point, but then later when the client executes step 4, it does not accurately read in the work packet because part of it has already been read into the buffer in step 2.
Solution I: The easiest solution is to have the server write the entire buffer in step 1, rather than just the part filled with the greeting, as:. Solution II: A better approach for handling variable-length strings is to first write the length of the string, followed by the string itself as a separate write. Under this solution the server code changes to:. Normally, the process ID is an integer. Moreover, a process can use function getpid to retrieve the process ID assigned to this process.
Let's solve. Vishal Goyal answered Feb 19, Pooja Palod answered Sep 22, Ans 6 is correct. Total process will be 8 including main.
Newly created child process will be 7. Since for n fork calls total child process will be 2 n - 1. IgnitorSandeep answered Sep 25, Thats for n fork calls in a loop or without any intermediate condition. Sorry sir. It's my fault. Including parent process, answer is 6. Divya Soni answered Apr 2, Next Qn. Answer: 6. Related questions 1 vote. How many process are created by the program?
Is there any easier method to solve this kind of question?? Na asked in Operating System May 25, Please see my solution carefully and point out weather the number of parent and child were calculated correctly? Mak Indus asked in Operating System Jan 11, How many processes will be created when we run the below program? Akriti sood asked in Databases Jun 7, How many diff B tree can be created with 6 records?
Subjects All categories General Aptitude 2. Follow gateoverflow. GATE Overflow. Recent Blog Comments Arjun gatecse where has this link been moved Its updated In the google drive sheet of test series, OS test Can you please tell me about the internship So, child process p1 will create p5,p6 and p7 and parent process will create p2, p3 and p4. After p2 has been created two more fork needs to be executed for this child thread p2 which was created after execution of 2nd fork statment.
In this way, this parent-child processes are created. Next, compile and run your program. Then run pstree to see what the process hierarchy looks like. Goodluck :. This solution inspired by OS reference books that means the parent process at each level goes to the next branch and the previous branch terminates, because of this we just count leafs.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. OS: How many process are created by the program? Ask Question. Asked 7 years, 11 months ago. Active 3 days ago. Viewed 41k times. Improve this question. Steven Chou Steven Chou 1 1 gold badge 13 13 silver badges 35 35 bronze badges.
0コメント