DOC PREVIEW
UB CSE 421 - Process Description and Control in Unix

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 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 21 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 21 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 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Process Description and Control in UnixCreation of a processProcess InterruptionUnix system VUNIX SVR4 Process StatesUNIX Process State DiagramProcess and kernel contextUnix system V (contd.)U areaProc structureProcess ContextUNIX Process ImageSlide 13Process images in virtual memoryProcess controlProcess control (contd.)UNIX Process CreationProcess creation - Examplefork and execExampleVersion of exec01/16/19 1Process Description and Control in UnixB. RamamurthySpring 200701/16/19 2Creation of a process•A unique pid is assigned to the new process.•Space is allocated for all the elements of the process image. •The process control block is initialized. Inherit info from parent.•The appropriate linkages are set: for scheduling, state queues..•Create and initialize other data structures (file tables, IO table etc.).01/16/19 3Process Interruption•Two kinds of process interruptions: interrupt and trap.•Interrupt: Caused by some event external to and asynchronous to the currently running process, such as completion of IO.•Trap : Error or exception condition generated within the currently running process. Ex: illegal access to a file, arithmetic exception.•(supervisor call) : explicit interruption.01/16/19 4Unix system V•All user processes in the system have as root ancestor a process called init. When a new interactive user logs onto the system, init creates a user process, subsequently this user process can create child processes and so on. init is created at the boot-time.•Process states : User running , kernel running, Ready in memory, sleeping in memory (blocked), Ready swapped (ready-suspended), sleeping swapped (blocked-suspended), created (new), zombie , preempted (used in real-time scheduling).01/16/19 5UNIX SVR4 Process States•Similar to our 7 state model•2 running states: User and Kernel–transitions to other states (blocked, ready) must come from kernel running•Sleeping states (in memory, or swapped) correspond to our blocking states•A preempted state is distinguished from the ready state (but they form 1 queue)•Preemption can occur only when a process is about to move from kernel to user mode01/16/19 6UNIX Process State Diagram01/16/19 7Process and kernel contextUser modemodekernelprocess contextkernel contextApplication pgmssystem callskernel tasksinterrupt servicesKernel acts on behalf of user01/16/19 8Unix system V (contd.)•What does unix process image contain? •What does process table entry contain? proc•What is unix U (user) area? u area•Function of each of these components.•Explore code in /usr/include/sys/user.h, proc.h, etc.01/16/19 9U area •Process control block•Pointer to proc structure (process table entry)•Signal handlers related information•Memory management information•Open file descriptor•Vnodes(?) of the current directory•CPU usage stats01/16/19 10Proc structure•Identification•Process state•Scheduling priority + other related info.•Signal handling info•Memory management info•Sleep channel for blocked processes•Location to kernel map of u area of the process•Flags•Process hierarchy info01/16/19 11Process Context•User address space,•Control information : u area (accessed only by the running process) and process table entry (or proc area, accessed by the kernel)•Credentials : UID, GID etc.•Environment variables : inherited from the parent01/16/19 12UNIX Process Image•User-level context–Process Text (ie: code: read-only)–Process Data–User Stack (calls/returns in user mode) –Shared memory (for IPC)•only one physical copy exists but, with virtual memory, it appears as it is in the process’s address space•Register context01/16/19 13UNIX Process Image•System-level context–Process table entry (proc)•the actual entry concerning this process in the Process Table maintained by OS–Process state, UID, PID, priority, event awaiting, signals sent, pointers to memory holding text, data...–U (user) area•additional process info needed by the kernel when executing in the context of this process–effective UID, timers, limit fields, files in use ...–Kernel stack (calls/returns in kernel mode)–Per Process Region Table (used by memory manager)01/16/19 14Process images in virtual memory01/16/19 15Process control•Process creation in unix is by means of the system call fork(). •OS in response to a fork() call:–Allocate slot in the process table for new process.–Assigns unique pid.–Makes a copy of the process image, except for the shared memory.–Move child process to Ready queue. –it returns pid of the child to the parent, and a zero value to the child.01/16/19 16Process control (contd.)•All the above are done in the kernel mode in the process context. When the kernel completes these it does one of the following as a part of the dispatcher:–Stay in the parent process. Control returns to the user mode at the point of the fork call of the parent.–Transfer control to the child process. The child process begins executing at the same point in the code as the parent, at the return from the fork call.–Transfer control another process leaving both parent and child in the Ready state.01/16/19 17UNIX Process Creation•Every process, except process 0, is created by the fork() system call–fork() allocates entry in process table and assigns a unique PID to the child process–child gets a copy of process image of parent: both child and parent are executing the same code following fork()–but fork() returns the PID of the child to the parent process and returns 0 to the child process01/16/19 18Process creation - Examplemain () { int pid; cout << “ just one process so far”<<endl; pid = fork(); if (pid == 0) cout <<“I am the child “<< endl; else if (pid > 0) cout <<“I am the parent”<< endl; else cout << “fork failed”<< endl;}01/16/19 19fork and exec•Child process may choose to execute some other program than the parent by using exec call.•Exec overlays a new program on the existing process.•Child will not return to the old program unless exec fails. This is an important point to remember.•Why does fork need to clone?•Why do we need to separate fork and exec? •Why can’t we have a single call that fork a new program?01/16/19 20Exampleif (( result = fork()) == 0 ) { // child code if (execv (“new program”,..) < 0) perror (“execv failed “); exit(1);} else if


View Full Document

UB CSE 421 - Process Description and Control in Unix

Documents in this Course
Security

Security

28 pages

Threads

Threads

24 pages

Security

Security

20 pages

Security

Security

52 pages

Security

Security

20 pages

Load more
Download Process Description and Control in Unix
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 Process Description and Control in Unix 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 Process Description and Control in Unix 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?