MESSAGE
DATE | 2015-03-16 |
FROM | mrbrklyn@panix.com
|
SUBJECT | Subject: [LIU Comp Sci] Operating Systems Chapter 3 HW complete
|
From owner-learn-outgoing-at-mrbrklyn.com Mon Mar 16 15:18:20 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id 389D91612E7; Mon, 16 Mar 2015 15:18:20 -0400 (EDT) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 25FDB1612EB; Mon, 16 Mar 2015 15:18:20 -0400 (EDT) Delivered-To: learn-at-nylxs.com Received: by mrbrklyn.com (Postfix, from userid 1000) id B0C9A1612E9; Mon, 16 Mar 2015 15:18:19 -0400 (EDT) Date: Mon, 16 Mar 2015 15:18:19 -0400 From: mrbrklyn-at-panix.com To: learn-at-nylxs.com Subject: [LIU Comp Sci] Operating Systems Chapter 3 HW complete Message-ID: <20150316191819.GA31735-at-www.mrbrklyn.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.21 (2010-09-15) Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
--17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline
This is all of the chapter 3 question and one programming project.
I wanted to do more of the programming projects but I've been busy working on a virtual server and testing custom kernel compiles for our scheduler project, which I wanted just finish and get off my plate. The Kernel is so large now and difficult to set up the config file that is takes more time. It doesn't help to have hostile developers now who think users aren't supposed to ask about kernel internals. This makes me fustrated. When did it happen that asking to compile a kernel is offensive to distribution developers and that development tools became exclussive property of the few??
Umbuntu, and the Umbuntu attitude really is crushing the Linux community.
Ruben
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013
--17pEHd4RhPHOinZp Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="hw_os_cpt3.txt" Content-Transfer-Encoding: 8bit
Practice Exercises 3.1 Using the program shown in Figure 3.30, explain what the output will be at LINE A.
Answer: A is 5
#include #include #include int value = 5;
int main() { pid t pid; pid = fork(); if (pid == 0) { /* child process */ value += 15; return 0; } else if (pid > 0) { /* parent process */ wait(NULL); printf("PARENT: value = %d",value); /* LINE A */ return 0; } }
3.2 Including the initial parent process, how many processes are created by the program shown in Figure 3.31?
Answer: Eight!!!
xterm???bash???a.out???a.out???a.out???a.out ? ? ??a.out ? ??a.out???a.out ? ??a.out
#include#include
int main() { /* fork a child process */ fork(); /* fork another child process */ fork(); /* and fork another */ fork(); return 0; } Figure 3.31 How many processes are created?
3.3 Original versions of Apple’s mobile iOS operating system provided no means of concurrent processing. Discuss three major complications that concurrent processing adds to an operating system.
Answer: memory requiements are larger with + multisourced oses, longer wait times for i/o an ready cues since there is a limited schedular without concurency, but the application that is running reacts faster since there is no CPU overhead for short term scheduling.
Few registers are needed on the CPU for quick concurancy contact swaps.
3.4 The Sun UltraSPARC processor has multiple register sets. Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.
Answer: On the hardware level, registers are just switched, and the program counter just reset, rather than the entire context tossed on the stack.
What happens if the new context is in memory rather than in a register set and all the register sets are in use?
All the context has to be rebuilt off the stack a, and all the active registers have to be reset to the saved condition.
3.5 When a process creates a new process using the fork() operation, which of the following states is shared between the parent process and the child process? a. Stack b. Heap c. Shared memory segments
Answer: Share Memory segments.
3.6 Consider the “exactly once”semantic with respect to the RPC mechanism. Does the algorithm for implementing this semantic execute correctly even if the ACK message sent back to the client is lost due to a network problem? Describe the sequence of messages, and discuss whether “exactly once” is still preserved.
If a client demanding a RPC doesn't retreive the ACK under the exactly once semantic, then it will time out and send another request to the server. Each request as a time stamp, and when the server sees the duplicate, it will not open another request, but send a new ack instead.
3.7 Assume that a distributed system is susceptible to server failure. What mechanisms would be required to guarantee the “exactly once” semantic for execution of RPCs?
What is he fishing for here? This was just explained.
3.8 Describe the differences among short-term, medium-term, and long- term scheduling.
Short term Scheduling is the rotation of all processes on the ready cue to get cpu time.
Long Term scheduling is used to balance types of process usage and to keep resources management from running away.
medium-term scheduling will roll processes tepmorarily off of the ready cue when cpu time is tied up, and load processes onto swap.
#include#include
int{ main() int i; Exercises for (i = 0; i < 4; i++) fork(); return 0; } Figure 3.32 How many processes are created?
3.9 Describe the actions taken by a kernel to context-switch between processes.
When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. Virtual address space might need to be saved as well
3.10 Construct a process tree similar to Figure 3.8. To obtain process infor- mation for the UNIX or Linux system, use the command ps -ael.
[ruben-at-stat13 ~]$ pstree -Ap init(1)-+-NetworkManager(2364)-+-dhclient(2509) | |-{NetworkManager}(2365) | |-{gdbus}(2377) | `-{gmain}(2376) |-acpid(2273) |-agetty(2849) |-agetty(2850) |-agetty(2851) |-agetty(2852) |-agetty(2853) |-agetty(2854) |-at-spi-bus-laun(5511)-+-dbus-daemon(5515) | |-{dconf worker}(5512) | |-{gdbus}(5514) | `-{gmain}(5516) |-at-spi2-registr(5518)---{gdbus}(5520) |-avahi-daemon(2610)---avahi-daemon(2611) |-colord(2728)-+-{gdbus}(2730) | `-{gmain}(2731) |-console-kit-dae(2335)-+-{gdbus}(2360) | |-{gmain}(2358) | |-{vt_thread_start}(2355) | `-{writer_thread_s}(2340) |-crond(2588) |-cupsd(2726)---{cupsd}(2734) |-dbus-daemon(2314) |-dbus-daemon(2986) |-dbus-launch(2985) |-dconf-service(5562)-+-{gdbus}(5564) | `-{gmain}(5565) |-gvfs-udisks2-vo(5420)-+-{gdbus}(5421) | `-{gmain}(5422) |-gvfsd(3013)---{gdbus}(3014) |-gvfsd-cdda(5430)---{gdbus}(5431) |-gvfsd-fuse(3017)-+-{gdbus}(3027) | |-{gvfs-fuse-sub}(3028) | |-{gvfsd-fuse}(3025) | `-{gvfsd-fuse}(3026) |-gvfsd-metadata(5537)---{gdbus}(5539) |-gvim(3802)---{gdbus}(3803) |-kactivitymanage(3139)-+-{QInotifyFileSys}(3146) | |-{QThread}(3143) | |-{QThread}(3144) | |-{QThread}(3145) | |-{QThread}(3147) | `-{QThread}(5390) |-kded4(3041)---{QInotifyFileSys}(3275) |-kdeinit4(3037)---klauncher(3039) |-knotify4(3271)---{QInotifyFileSys}(3272) |-kuiserver(3701) |-lxdm-binary(2544)-+-Xorg.bin(2587)---{Xorg.bin}(2732) | `-lxdm-session(2882)---wmaker(2889)---wmaker(2988)-+-oclock(2992) | |-xterm(2993)---bash(3004)---pstree(5869) | |-xterm(2994)---bash(3003) | |-xterm(3790)---bash(3792) | |-xterm(4911)---bash(4913)---okular(5616)-+-{QI+ | | `-{QP+ | `-xterm(5394)---bash(5396) |-metalog(2224)---metalog(2225) |-ntpd(2781) |-oclock(3000) |-pidgin(2999)---{gdbus}(3011) |-polkitd(2362)-+-{gdbus}(2378) | |-{gmain}(2363) | |-{polkitd}(2379) | `-{runaway-killer-}(2380) |-rsyslogd(2248)-+-{in:imklog}(2250) | |-{in:imuxsock}(2249) | `-{rs:main Q:Reg}(2251) |-sshd(2804) |-udevd(699) |-udisksd(3093)-+-{cleanup}(3111) | |-{gdbus}(3109) | |-{gmain}(3107) | `-{probing-thread}(3110) |-upowerd(3048)-+-{gdbus}(3050) | `-{gmain}(3049) `-wicd(2408)---wicd-monitor(2478)
Use the command man ps to get more information about the ps com- mand. The task manager on Windows systems does not provide the parent process ID, but the process monitor tool, available from tech- net.microsoft.com, provides a process-tree tool.
3.11 Explain the role of the init process on UNIX and Linux systems in regard to process termination.
init is the system program that launches all the services that control the GNU/Linux system. It is the root process and waits for all the child processes. Ultimately it cleans zombie processes.
Its roll has been dramatically expanded and changed with the advent of systemd, and no longer are the processes just spun off and waited for. Instead, many core functions have been built directly into the init binary.
The initiation system for Linux has evolved over the years from a BSD proc system to what was then called SySV and now we have systemd, or the competing openrc. Emphasis on fail over and remote usage has pushed comercial vendors to a more integrated approch in systemd at process 1.
3.12 Including the initial parent process, how many processes are created by the program shown in Figure 3.32?
#include #include int main() { int i; for (i = 0; i < 4; i++) fork(); return 0; }
Figure 3.32
This is the same as before and creates 8 processes
P -> P2 -----> P3 -> P4 | | P3 ->P4 P4 | P4
3.13 Explain the circumstances under which which the line of code marked printf("LINE J") in Figure 3.33 will be reached.
ANSWER: NONE
man execlp The exec() family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for execve(2). (See the manual page for execve(2) for fur? ther details about the replacement of the current process image.)
#include #include #include int main() { pid t pid; /* fork a child process */ pid = fork();
if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); return 1; } else if (pid == 0) { /* child process */ execlp("/bin/ls","ls",NULL); printf("LINE J"); } else { /* parent process */ /* parent will wait for the child to complete */ wait(NULL); printf("Child Complete"); } }
3.14 Using the program in Figure 3.34, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the parent and child are 2600 and 2603, respectively.)
#include #include #include
int main() { pid_t pid, pid1; /* fork a child process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); return 1; } else if (pid == 0) { /* child process */ pid1 = getpid(); printf("child: pid = %d",pid); /* A */ printf("child: pid1 = %d",pid1); /* B */ } else { /* parent process */ pid1 = getpid(); printf("parent: pid = %d",pid); /* C */ printf("parent: pid1 = %d",pid1); /* D */ wait(NULL); } return 0; }
A = 0 B = 2603 C = 2603 D = 2600
Figure 3.34 What are the pid values? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #include #include #define SIZE 5 int nums[SIZE] = {0,1,2,3,4}; int main() { int i; pid t pid; Exercises pid = fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { nums[i] *= -i; printf("CHILD: %d ",nums[i]); /* LINE X */ } } else if (pid > 0) { wait(NULL); for (i = 0; i < SIZE; i++) printf("PARENT: %d ",nums[i]); /* LINE Y */ } } return 0; Figure 3.35
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3.15 Give an example of a situation in which ordinary pipes are more suitable than named pipes and an example of a situation in which named pipes are more suitable than ordinary pipes.
One a services that has multiple child processes to talk to then ordinary pipes are more useful. And example might be the Apache Web Server where multiple children are spun off the parent and communication with the parent.
However, a named pipe is needed for any communication between two seperate processes. It you need a music stream, for example, you be sent through a service, you will need a named pipe for the streamer to talk to and the server will have to read from the pipe.
3.16 Consider the RPC mechanism. Describe the undesirable consequences that could arise from not enforcing either the “at most once” or “exactly once” semantic. Describe possible uses for a mechanism that has neither of these guarantees.
If timestamps are not compared and at most once of exactly once semantics are not used then clients can not be assured that the data stream is correct if they don't recieve a return message. The system is then fully dependent of the physical perfection of the intrastructure for communication assurance.
3.17 Using the program shown in Figure 3.35, explain what the output will be at lines X and Y.
Parent 0,1,2,3,4 Child 0,-1,-2,-3,-4
3.18 What are the benefits and the disadvantages of each of the following? Consider both the system level and the programmer level. a. Synchronous and asynchronous communication Synchronous communications are slower and will cause latency problem but guantanty communications with lower overhead as more communication is blocked until sending matches recieving.
b. Automatic and explicit buffering The text doesn't explain explicit buffering, but automatic buffering has the advantage of having bound or infinite buffering space which allows for lower message latency and few or no sender blocks.
I think the textbook maybe is messed up in this spot and needs rediting.
I would thing explicit buffering is any finetely defined buffering on the communications que, which is GOOD and SECURE even though it requires sender blocks
INFINITE would be automatic and that is opimistic and NOT secure.
c. Send by copy and send by reference Send by copy is a problem with MACH kernels because several copies of information is made. It is essential for distributed systems but for smaller systems that share memory references can lower the system overhead.
d. Fixed-sized and variable-sized messages Fixed sized messages give certainty of buffer needs and sizes and variable messages allow for greater optimizations
Programming Problems 3.19 Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command ps -l
#include #include #include #include #include
int main( int argc, char * argv[]){ pid_t pid; int i = 0; puts("\nBefore the While Loop"); while( i++ < 100){ puts("\nBefore the Fork in the Loop:"); printf( "Loop ==> %d \n", i); pid = fork(); puts("\nFork: This should print twice for every loop:");
if(pid < 0){ puts( "fork failed\n" ); return 1; } if(pid == 0) { puts("\n\nChildren of the world unite"); printf("Am Yisrael Chai! pid =>%d \n", pid); printf( "Loop in Child ==> %d \n", i); puts("BYE!!"); exit( EXIT_SUCCESS ); } if (pid > 0 ){ printf("In the Parent => I'm waiting %d\n", pid ); printf( "Loop in Parent ==> %d \n", i); //wait(NULL); puts("Done Waiting for Child"); } } return 0; }
18456 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18457 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18458 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18459 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18460 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18461 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18462 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18463 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18464 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18465 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18466 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18467 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out 18468 ruben 20 0 0.0m 0.0m 0.0 0.0 0:00.00 Z `- a.out
~~~~~~~~~~~~
--17pEHd4RhPHOinZp--
|
|