DOC PREVIEW
U of I CS 241 - System Programming Process

This preview shows page 1-2-3-26-27-28 out of 28 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS241 System ProgrammingProcessOverviewAdministrativeProcessesProcess ManagementAn AbstractionThread of ControlLocus of ControlConcurrent ProgramDiscussionMotivation for a ProcessProcessesThe Multiprogramming Process ModelProcess IdentificationProcess CreationCreating a Process in UnixUNIX ExampleProcess Operations (Creation)Process TerminationProcess Operations (Termination)Process HierarchiesWait FunctionWaiting for a child to finishStatus ValuesTypical process creation codeExec FunctionExec ExampleBackground Processes and DaemonsSummaryCS241 System ProgrammingProcessKlara NahrstedtLecture 31/25/061/25/2006CS 241 - System Programming, Klara Nahrstedt2Overviewz Process Conceptz Process Structure z Process Operationsz Summary1/25/2006CS 241 - System Programming, Klara Nahrstedt3Administrativez Read T: Chapter 2.1z Read R&R: Chapter 31/25/2006CS 241 - System Programming, Klara Nahrstedt4ProcesseszA process is an abstraction for sequence of operations that implement a computation. A process may be manipulated, suspended, scheduled and terminatedz Process is a unit of work in a modern computerz Process Types: –OS processes executing system code–User processes executing user codezProcesses are executed concurrently with CPU multiplexing among them1/25/2006CS 241 - System Programming, Klara Nahrstedt5Process ManagementzProcess is also used to describe concurrent user activities and many forms of parallel computation z A process is one of the key concepts underlying modern operating system design1/25/2006CS 241 - System Programming, Klara Nahrstedt6An AbstractionzIn a time-sharing system, the actual execution of the instructions of a process may become interleaved with other instructions of other processeszIn a multiprocessor system, the concurrent processes may each execute on an independent processor1/25/2006CS 241 - System Programming, Klara Nahrstedt7Thread of ControlzThe path that a computation taken through a program corresponding to the individual statements that are executed by a particular process1/25/2006CS 241 - System Programming, Klara Nahrstedt8Locus of ControlzThe end of the thread of control of a process marking the instruction that will be executed next1/25/2006CS 241 - System Programming, Klara Nahrstedt9Concurrent ProgramzA program that has many processes1/25/2006CS 241 - System Programming, Klara Nahrstedt10DiscussionzWhat mechanisms are needed to implement a process?z How does hardware architecture support the concept of a process?1/25/2006CS 241 - System Programming, Klara Nahrstedt11Motivation for a ProcesszProcess –Each process has an ``abstract'' locus of control–Any exchanges of control are done automatically and implicitly–Runs in parallel on multiprocessor1/25/2006CS 241 - System Programming, Klara Nahrstedt12ProcessesThe Multiprogramming Process ModelzMultiprogramming of four programszConceptual model of 4 independent, sequential processeszOnly one program active at any instant1/25/2006CS 241 - System Programming, Klara Nahrstedt13Process IdentificationzUNIX identifies processes via unique value –Process ID –Each process has also parent process ID since each process is created from a parent process. –Root process is the ‘init’ processz‘getpid’ and ‘getppid’ – functions to return process ID (PID) and parent process ID (PPID)#include <stdio.h>#include <unistd.h>int main (void) {printf(“I am process %ld\n”, (long)getpid());printf(“My parent id %ld\n”, (long)getppid());return 0; }1/25/2006CS 241 - System Programming, Klara Nahrstedt14Process CreationzSystem initialization–rebootzExecution of a process creation system call–Fork() : #include <unistd.h>pid_t fork(void);zUser request to create a new process–Command line or click an iconzInitiation of a batch job–CronzProcesses are created and deleted dynamically1/25/2006CS 241 - System Programming, Klara Nahrstedt15Creating a Process in Unix#include <stdio.h>#include <unistd.h>int main(void) {int x;x = 0;fork();x = 1;printf("I am process %ld and my x is %d\n", (long)getpid(), x);return 0;}1/25/2006CS 241 - System Programming, Klara Nahrstedt16UNIX Example#include <stdio.h>#include <unistd.h>#include <sys/types.h>int main(void) {pid_t parentpid;pid_t childpid;if ((childpid = fork()) == -1) {perror(can’t create a new process);exit(1);}else if (childpid == 0) {/* child process executes */printf(“child: childpid = %d, parentpid = %d \n”, getpid(), getppid());exit(0);}else { /*parent process executes */printf(“parent: childpid = %d, parentpid = %d \n”, childpid, getpid());exit(0);}1/25/2006CS 241 - System Programming, Klara Nahrstedt17Process Operations (Creation)zWhen creating a process, we need resources such as CPU, memory files, I/O devices–When creating a new process, process can get resources from the OS or from the parent process–When getting resources from a parent, this means that the child process is restricted to a subset of parent resources zPrevents many processes from overloading system–When creating a new process , execution possibilities are zParent continues concurrently with childzParent waits until child has terminated–When creating a new process, address space possibilities are:zChild process is duplicate of parent processzChild process had a program loaded into it1/25/2006CS 241 - System Programming, Klara Nahrstedt18Process TerminationzNormal exit (voluntary)–End of main()zError exit (voluntary)–exit(2)#include <stdlib.h>void exit(int status);zFatal error (involuntary)–Divide by 0, core dumpzKilled by another process (involuntary)–Kill procID, end task1/25/2006CS 241 - System Programming, Klara Nahrstedt19Process Operations (Termination)zWhen a process finishes last statement, it asks OS to delete itz Child process may return output to parent process, and all child’s resources are de-allocated. z Other termination possibilities–Abort by parent process invokedzChild has exceeded its usage of some resourceszTask assigned to child is no longer requiredzParent is exiting and OS does not allow child to continue without parent1/25/2006CS 241 - System Programming, Klara Nahrstedt20Process HierarchieszParent creates a child process, a child process can create its own processesz Forms a hierarchy–UNIX calls this a "process group"zWindows has no concept of process hierarchy–all processes are created equal1/25/2006CS 241 - System Programming, Klara Nahrstedt21Wait Functionerrno causeECHILD Caller has no unwaited-for


View Full Document

U of I CS 241 - System Programming Process

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download System Programming Process
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view System Programming Process and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view System Programming Process 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?