Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All of the questions below should be answered about a Linux system ( not Windows or xv 6 ) . Question 1 In chapter 5

All of the questions below should be answered about a Linux system (not Windows or xv6).
Question 1
In chapter 5, the example program p3.c calls wait(2) in the parent process. What happens if we call wait from the child process instead? Specifically what does wait(2) return? If it indicates an error, use the function perror(3) to print the error.
Question 2
In the manual page for execlp(3), the RETURN VALUE section indicates that it returns -1 on error. Is there any reason why we need to check the return value? In other words, given the snippet below, is the if statement necessary?
...
if (execlp("wc","wc","-l", NULL)==-1){
perror("execlp");
exit(1);
}
Or, is the following equivalent?
...
execlp("wc","wc","-l", NULL);
perror("execlp");
exit(1);
Explain your answer.
Question 3
execlp(3) is not a system call; it is a library function. Upon which system call is execlp(3) based in Linux? You can either use the technique in Question 4 or read the manual page.
Question 4
It should not be a surprise that printf(3) is a library function that ultimately calls write(2). Let's use the system call tracer, strace(1), to figure out what system call malloc(3) is based on. Compile the code below into a program called malloctest. Then run: strace ./malloctest. It will produce a lot of output, but we're only concerned with the last few lines. Look for the two calls to write(2). Between them is the system call upon which malloc(3) is based. What permissions are granted on memory allocated by malloc(3)? Also, what is the last system call executed by malloctest?
#include
#include
int
main(){
printf("Hello
");
printf("%p
", malloc(1000000));
return 0;
}
Question 5
If it takes a long time to switch back and forth between user and kernel mode for a system call, this can ultimately limit the performance of an operating system. Let's find out how long it takes to go from kernel to user and back. Since we want the kernel to do as little work as possible when our system call is used, let's pick on the write(2) system call. If it is given an invalid file descriptor, a NULL pointer, and a zero length, it will simply check for one of those conditions and fail, e.g. write(-1, NULL, 0);. If we get the current time before running this call many times and the time when we finish and then do a little arithmetic, we can determine the time cost of a single call. The system call, clock_gettime(CLOCK_REALTIME,...), uses a sufficiently precise timer for this exercise. How long does it take to perform N system calls (where N is 1,000,000) and how long does it take do 1?
Question 6
Given three jobs, A, B, C which take 200,100, and 300 units of time to complete. They arrive at the scheduler at very close to the same time, so that the scheduler can choose the ordering of the jobs simultaneously.
with the FIFO scheduler, the jobs are run in alphabetical order, what is the average turnaround time? what is the average response time?
with the SJF scheduler, what is the average turnaround time? What is the average response time?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions