1 / 9

UNIX PROCESSES

UNIX PROCESSES. These lecture notes are based on the lecture notes of Prof. Gimel’farb , Dr Riddle and Dr Nagra . Special thanks to them all…. OS. Virtually everything running under UNIX is a process Exception: Kernel

enrico
Download Presentation

UNIX PROCESSES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX PROCESSES These lecture notes are based on the lecture notes of Prof. Gimel’farb, Dr Riddle and Dr Nagra. Special thanks to them all…

  2. OS • Virtually everything running under UNIX is a process • Exception: Kernel • Kernel is a set of routines that resides continuously in memory and to which all processes have access • Kernel mode: a process has an unrestricted access to the CPU and hardware • User mode: a process is restricted • Hardware enforced: e.g., some I/O operations may not be allowed and memory areas may be inaccessible COMPSCI 215

  3. PID - the process-id; PPID - the parent PID The Process • A program or executable is a file loaded from disk • “Everything in UNIX is a file” • Once it is running, it is called a process • A UNIX process: • is identified by a unique process ID (PID) number • has an owner • has private data • The same program can be loaded more than once • creates multiple processes • each process has a different PID • PIDs are unique, non negative integers • numbers recycle without collisions • each process may have a different owner COMPSCI 215

  4. PID - the process-id; PPID - the patent PID The Process • Since UNIX is multitasking, hundreds or even thousands of processes can run on a large system • A process: • Is born when the program starts execution • Remains alive as long as the program is active • Dies after execution is complete • Has a name (usually, the name of the program being executed) • Is not synonymous with a program! COMPSCI 215

  5. PID - the process-id; PPID - the patent PID The Process • Except for the first process, every process has a parent • Processes are arranges in a hierarchical structure • Processes have attributes stored in the process table • Most attributes are inherited by the child from its parent COMPSCI 215

  6. SYSTEM PROCESSES • When the computer is switched on, it activates the memory-resident code stored in read-only memory (i.e. ROM) which are known collectively as the BIOS (i.e. basic input-output system) on the CPU board. • The memory-resident code runs some checks and reads the boot program from the boot device. • The boot program reads in the kernel and passes control to it. • Kernel identifies and configures the devices. • The kernel starts running by setting up internal tables. • These tables are used to keep track of running processes, memory allocation, open files, and a number of other things COMPSCI 215

  7. After initializing its tables, the kernel creates four dummy processes; sched, init,vhand and bdflush (with process IDs 0, 1, 2 and 3 respectively). • sched provides swapping services • init runs continuously; it is the parent of all other processes on the system. • Gives birth to every service running in the system (mail, printing, etc) • vhand provides virtual memory paging services, • bdflush flushes the buffer cache periodically. • When you log in, the process represented the shell (sh, ksh, csh, or bash) starts running at your terminal • The shell maintains a set of environmental variables like PATH and HOME; the shell’s own pathname is stored in SHELL and its PID is stored in a special “variable”, $$ COMPSCI 215

  8. Process States • At any instant of time, a process is in a particular state • A process after creation is in the runnable state (R) before it actually runs on the CPU (state running (O)) • When the running process has nothing to do except wait for a disk I/O operation to complete, it moves to the sleeping state (S) to be woken up when the I/O operation is over • A process can be suspended (T) by pressing a key (usually, Ctrl-z) • A process is in zombie state (Z) if it had terminated and had all its resources cleaned up by the kernel. • A zombie process’ PID remains in the system table, and, its return code and resource usage are stored for the parent to obtain. • A zombie process’ information will be removed from the system when its parent uses the wait system call to collect this information. • If the parent itself dies before the child dies, the child becomes an orphan and the kernel makes init the parent of all orphans COMPSCI 215

  9. Zombie Running in User Mode 6 3 exit 4 1 Running in Kernel Mode Context Switch New Process 2 5 Wakeup Ready to Run Sleeping Process Life Cycle • New process has no state • Process is ready to run but does not have CPU • Context switch occurs and the process runs • System call occurs and the process switches to kernel mode • Process tries a slow operation, so it is put to sleep • Process calls a system call to exit and becomes a zombie COMPSCI 215

More Related