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

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse 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

Related Homework Solutions

Shell Scripts & Programming Language C
Homework Solution
$30.00
Linux
Shell Scripts
Computer Science
Programming Language C
Lowercase
Uppercase
Backup Directory
Algorithms
File Management
Printing Messages
TCSH
VI Editor Exercises
Homework Solution
$25.00
Vi
Editor
Edit
File
Copy
Paste
Home
Directory
Screenshot
Output
Insert
Save
Computer
Science
Linux
Shell
Scripting
Linux Scripting Final Task
Homework Solution
$58.00
UNIX
Command
Find
Hosts
Pipe
Grep
Passwd
Csh
Cd
Link
Blink
Symbolic
Mailx
PID
Process
Lpsched
Root
Awk
Smcgowan
Usr
Bin
Linux & C++ Problems
Homework Solution
$30.00
Computer Science
Linux
C++
Functions
Statements
Variables
Loops
Conditions
File Management
Commands
Codes
Child Processes
Command Line
Parent Processes
Executable Program
Buffers
Forks
Operators
Three Simple Shell Scripts
Homework Solution
$15.00
Shell
Bash
Script
List
Directory
Lsdirs
Sh
File
See
Wordlen
Type
Long
Word
Test
Read
Wc
Argument
Bourne
Get help from a qualified tutor
Live Chats