Answer the following questions: 1. Including the initial parent...

Question
Answer the following questions:

1. Including the initial parent process, how many processes are created by the following process? Explain in few lines.
#include <stdio.h>
#include<unistd.h>
Int main()
{
/*fork a child process */
fork();
/*fork another child process */
fork();
/*fork a child process */
fork();
return 0;
}

2. Consider the following code segment:
pid pid;
pid =fork();
if (pid == 0) {/*child process */
fork();
thread_create(…);
}
fork();
a. How many unique processes are created?
b. How many unique threads are created?

3. Design a program using ordinary pipes in which one process sends a string message to a second process, and the second process reverses the case of each character in the message and sends back to the first process. For example, if the first process sends the message Hello, the second process will return olleh. This will require using two pipes, one for sending the original message from the first to the second process and other for sending the modified message from the second to the first process. Write it using UNIX pipes.

4. Write a program in C language for server and client, client should get date from server and client displays it, it should be done using socket.

5. A multithreaded web server wishes to keep track of the number of requests it services (known as hits). Consider the two following strategies to prevent a race condition on the variable hits. The first strategy is to use a basic mutex lock when updating hits:
int hits;
mutex_lock hit_lock;
hit_lock.acquire();
hits++;
hit_lock.release();
A second strategy is to use an atomic integer:
atomic_t hits;
atomic_inc(&hits);
Explain which of these two strategies is more efficient.

6. Race conditions are possible in many computer systems. Consider a banking system that maintains an account balance with two functions: deposit (amount) and withdraw (amount). These two functions pass the amount that is to be deposited or withdrawn from the bank account . Assume that a husband and wife share a bank account. Concurrently, the husband calls the withdraw () function and the wife calls deposit (). Describe how a race condition is possible and what might be done to prevent the race condition from occurring.

7. Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use nonpreemptive scheduling, and base all decisions on the information you have at the time the decision must be made.
a. What is the average turnaround time for these processes with the FCFS scheduling algorithm?
b. What is the average turnaround time for these processes with the SJF scheduling algorithm?
c. The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be called future-knowledge scheduling.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

1.
A total of 8 processes are created by the script.
The process forks at each fork(), thus not only does the original parent process fork but also its child processes. That is, since at at each fork() the number of existing processes is doubled, a total of 2 to the
power of 3 processes result.

2.
a.
6 unique processes are created; the parent is forked (2), and the child is forked yet again (1+2=3). All processes are forked again (3*2=6).

b.
8 unique threads are created. All unique processes are threads themselves (6), additionally, off the original process the child is forked; an additional thread is created, for each of the two (6+2=8).
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.docx
Purchase Solution
$13.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 640 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,804+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,680+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,428+ sessions)
2 hours avg response

Similar Homework Solutions