unix process control

Views:
 
Category: Entertainment
     
 

Presentation Description

Unix process control

Comments

Presentation Transcript

Process Concept:

Operating System Concepts Process Concept An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks Process – a program in execution; process execution must progress in sequential fashion. A process includes: Text segment Program counter Data segment Stack

Process State:

Operating System Concepts Process State As a process executes, it changes state new : The process is being created. running : Instructions are being executed. waiting : The process is waiting for some event to occur. ready : The process is waiting to be assigned to a process. terminated : The process has finished execution.

Process Control Block (PCB):

Operating System Concepts Process Control Block (PCB) Information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

Process Scheduling Queues:

Operating System Concepts Process Scheduling Queues Job queue – set of all PCBs in the system. Ready queue – set of all processes residing in main memory, ready and waiting to execute. Device queues – set of processes waiting for an I/O device. PCB migration between the various queues.

Ready Queue And Various I/O Device Queues:

Operating System Concepts Ready Queue And Various I/O Device Queues

Representation of Process Scheduling:

Operating System Concepts Representation of Process Scheduling

Context Switch:

Operating System Concepts Context Switch When CPU switches to another process, the system must Save the state of the old process Load the saved state for the new process. Context-switch time is overhead; the system does no useful work while switching. Time dependent on hardware support.

CPU Switch From Process to Process:

Operating System Concepts CPU Switch From Process to Process

Dispatcher:

Operating System Concepts Dispatcher Dispatcher module gives control of the CPU to the process selected by the CPU scheduler. This involves: Switching context Switching to user mode Setting the PC Dispatch latency is the time taken to stop one process and start another

Process Creation:

Operating System Concepts Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes. Resource sharing (one of) Parent and children share all resources. Children share subset of parent’s resources. Parent and child share no resources. Address space (one of) Child duplicate of parent. Child has a program loaded into it. Execution (one of) Parent and child execute concurrently. Parent waits until child terminate.

Process Termination:

Operating System Concepts Process Termination Process executes last statement and tells the OS Output status from child to parent Process’ resources are deallocated by operating system. Parent may terminate execution of children processes Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting (options) Operating system does not allow child to continue if its parent terminates. Cascading termination.

The Startup Sequence:

Operating System Concepts The Startup Sequence Initialize registers Put ROM start address (or indirect address) in PC Start interrupt?-fetch-decode-execute cycle Load OS from disk to RAM Start OS processes, including terminal logins and daemons Wait for interrupt

UNIX PCBs:

Operating System Concepts UNIX PCBs Control blocks associated with a process are stored in the kernel. Information in these control blocks is used by the kernel for process control and CPU scheduling. The virtual address space of a user process is divided into text (program code), data, and stack segments. Every process with sharable text has a pointer from its process structure to a text structure . Always resident in main memory. Records how many processes are using the text segment Records where the page table for the text segment can be found on disk when it is swapped.

Finding parts of a process using process structure :

Operating System Concepts Finding parts of a process using process structure

Allocating a New Process Structure:

Operating System Concepts Allocating a New Process Structure fork allocates a new process structure for the child process, and copies the user structure. New page table is constructed New main memory is allocated for the data and stack segments of the child process Copying the user structure preserves open file descriptors, user and group identifiers, signal handling, etc.

Process Control in UNIX:

Operating System Concepts Process Control in UNIX Processes are identified by their process identifier, an integer. Process control system calls fork creates a new process execve is used after a fork to replace on of the two processes’s virtual memory space with a new program exit terminates a process A parent may wait for a child process to terminate; wait provides the process id of a terminated child so that the parent can tell which child terminated. wait allows the parent to collect performance statistics about the child A zombie process results when the parent of a defunct child process exits before the terminated child.

Illustration of Process Control Calls:

Operating System Concepts Illustration of Process Control Calls

Process Hierarchy:

Operating System Concepts Process Hierarchy All user processes are descendants of one original process, init . init forks a getty process: Initializes terminal line parameters and passes the user’s login name to login . login sets the numeric user identifier of the process to that of the user Executes a shell which forks subprocesses for user commands.

UNIX Process Hierarchy:

Operating System Concepts UNIX Process Hierarchy

Process Privileges:

Operating System Concepts Process Privileges setuid bit sets the effective user identifier of the process to the user identifier of the owner of the file, and leaves the real user identifier as it was. setuid scheme allows certain processes to have more than ordinary privileges while still being executable by ordinary users.

Process Groups:

Operating System Concepts Process Groups Set of related processes that cooperate to accomplish a common task. Only one process group may use a terminal device for I/O at any time. The foreground job has the attention of the user on the terminal. Background jobs – nonattached jobs that perform their function without user interaction. Access to the terminal is controlled by process group signals.

Process Groups:

Operating System Concepts Process Groups Each job inherits a controlling terminal from its parent. If the process group of the controlling terminal matches the group of a process, that process is in the foreground. SIGTTIN or SIGTTOU freezes a background process that attempts to perform I/O; if the user foregrounds that process, SIGCONT indicates that the process can now perform I/O. SIGSTOP freezes a foreground process.

Signals:

Operating System Concepts Signals Facility for handling exceptional conditions similar to software interrupts. The interrupt signal, SIGINT, is used to stop a command before that command completes (usually produced by ^C). Signal use has expanded beyond dealing with exceptional events. Start and stop subprocesses on demand SIGWINCH informs a process that the window in which output is being displayed has changed size. Deliver urgent data from network connections.

Threads:

Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: Program counter Register set Stack space A thread shares with its peer threads its: Code segment Data segment Operating-system resources Collectively known as a task. A traditional or heavyweight process is equal to a task with one thread.

Single and Multithreaded Processes:

Operating System Concepts Single and Multithreaded Processes

Benefits:

Operating System Concepts Benefits Responsiveness Threads provide a mechanism that allows sequential processes to make blocking system calls while also achieving parallelism. In a multiple threaded task, while one thread is blocked and waiting, a second thread in the same task can run. Resource Sharing Economy Utilization of MP Architectures

Thread Implementations:

Operating System Concepts Thread Implementations User-level threads library POSIX Pthreads Mach C-threads Solaris threads Kernel Threads Windows 95/98/NT/2000 Solaris Linux

Many-to-One:

Operating System Concepts Many-to-One Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads.

One-to-One:

Operating System Concepts One-to-One Each user-level thread maps to kernel thread. Examples Windows 95/98/NT/2000 OS/2

Many-to-Many Model:

Operating System Concepts Many-to-Many Model Allows many user level threads to be mapped to many kernel threads. Allows the operating system to create a sufficient number of kernel threads. Solaris 2 Windows NT/2000 with the ThreadFiber package

Pthreads:

Operating System Concepts Pthreads A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. API specifies behavior of the thread library, implementation is up to development of the library. Common in UNIX operating systems.

authorStream Live Help