Chapter 3 : Process Management
Process Concept
Process – a program in execution; process execution
must progress in sequential fashion
• Multiple parts
• The program code, also called text section
• Current activity including program counter,
processor registers
• Stack containing temporary data
• Function parameters, return addresses, local
variables
• Data section containing global variables
• Heap containing memory dynamically allocated
during run time
Process Concept
• Program is passive entity stored on disk (executable file), process is
active
• Program becomes process when executable file loaded into memory
• Execution of program started via GUI mouse clicks, command line entry of
its name, etc
• One program can be several processes
• Consider multiple users executing the same program
Process States
As a process executes, it changes state
1. new: The process is being created
2. running: Instructions are being executed
3. waiting: The process is waiting for some event to occur
4. ready: The process is waiting to be assigned to a processor
5. terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Each process is represented in the operating system by a
Process Control Block (PCB).
Information associated with each process will be in PCB
(also called task control block)
• Process state – running, waiting, etc
• Program counter – location of instruction to next
execute
• CPU registers – contents of all process-centric registers
• CPU scheduling information- priorities, scheduling
queue pointers
• Memory-management information – memory allocated
to the process
• Accounting information – CPU used, clock time elapsed
since start, time limits
• I/O status information – I/O devices allocated to
process, list of open files
Operations on Processes
Operating System must provide mechanisms for: process creation,
process termination.
Processes Creation
• Process Creation: A process may create several new processes via create process
system call. Creating process is called Parent process and new processes are called
children processes which, in turn create other processes, forming a tree of processes
• Generally, process identified and managed via a process identifier (pid) which is
typically an integer.
Ex: Process tree for Solaris OS:
⁻ sched process: Top of the tree with pid 0. Creates several children processes – including
pageout, fsflush and init.
⁻ pageout and fsflush: Responsible for managing memory and file system.
⁻ init process : serve as the root parent process for all user processes. Eg: inetd and dtlogin
⁻ inetd: responsible for networking services such as telnet and ftp
⁻ dtlogin: represent a user login screen
⁻ Xsession: When user logs in, dtlogin creates an X-window session (Xsession)
⁻ Which in turn creates sdt_shell process.
⁻ C-shell: user’s command line shell, created at below sdt_shell in which user invokes
various child processes such as ls and cat commands.
⁻ C-shell process with pid 7778 created when user log onto the system using telnet.
⁻ This user can start Netscape browser and emacs editor.
A Tree of Processes in Solaris
Sched
Pid=0
init pageout fsflush
Pid=1 Pid=2 Pid=3
inetd
Pid= 140 dtlogin
Pid=251
Xsession
telnetdaemon Pid=294
Pid=7776
Sdt_shell
Pid=340
Csh
Pid=7778
Csh
Pid=1400
netscape emacs
Pid=7785 Pid=8105
cat
ls Pid=2536
Pid=2123
Processes Creation
Resource sharing: Process needs resources to accomplish its task.
• Resource sharing options : Parent and children(subprocesses) share all resources
Children share subset of parent’s resources
Parent and child share no resources
• Initialization data also passed along with resources by parent process to the child
process.
Ex: filename which contents to be display on the screen.
Execution: When process creates new process, there exist two execution options
• Parent and children execute concurrently
• Parent waits until some or all of its children have terminated
Address Space: Two possibilities for the address space of the child relative to the
parent
1. The child may be an exact duplicate of the parent, sharing the same program
and data segments in memory. Each will have their own PCB, including program
counter, registers, and PID. This is the behavior of the fork system call in UNIX.
Processes Creation
2. The child process may have a new program loaded into its address space, with
all new code and data segments. This is the behavior of the spawn system calls
in Windows. UNIX systems implement this as a second step, using
the exec system call.
Illustration of these difference with UNIX OS example
• fork() system call creates new process. New process consists of a copy of the
address space of the original process. This mechanism allows the parent process
to communicate easily with its child process.
• Both parent and child processes continue execution at the instruction after the
fork(), with one difference: return code of fork() – zero for new (child) process,
(nonzero) process identifier of the child to the parent process, so the return value
indicates which process is which.
• exec() system call used after a fork() system-call by one of the two processes to
replace the process’ memory space with a new program. exec() system call loads
a binary file into memory and starts its execution. The parent can then create
more children or if it has nothing else to do while the child runs, it can issue a
wait() system call to move itself off the ready queue until the child termination.
Operations on Processes
Creating a separate process using the UNIX fork( ) system call.
Processes Creation
• In the program pid for the child process is 0, that for the parent is an integer
greater than 0(i.e pid of the child process).
• The child process then cover its address space with UNIX command /bin/ls (Use
to get directory listing) using execlp() system call. execlp() is a version of the
exec() system call.
• The parent waits for the child process to complete with the wait() system call.
When the child process completes, by invoking exit() either implicitly or explicitly,
the parent process resumes from the call to wait().
• This is illustrated in below figure.
Processes Termination
• A process terminates when it finishes executing its last statement and then asks
the operating system to delete it using the exit() system call.
• Process returns status data (typically an integer) to its parent process (via
wait())
• All the resources of the process including physical and virtual memory, open
files, and I/O buffers are deallocated by operating system
• Parent process may terminate the execution of children processes using the
abort() (TerminateProcess() in Win32)system call.
• This system call only invoked by the parent of process that is to be terminated.
• Parent must know the identities of its children. So when process creates new
process , the identity of the newly created process is passed to the parent.
• Some reasons for doing so:
• Child has exceeded its usage of some of the allocated resources
• Task assigned to child is no longer required
• The parent is exiting and the operating systems does not allow a child to
continue if its parent terminates
Processes Termination
• Some operating systems do not allow child to exists if its parent has terminated.
If a parent process terminates, then all its children must also be terminated.
This phenomenon is to as cascading termination (All children, grandchildren,
etc. are terminated). The termination is initiated by the operating system.
Ex: To illustrate process termination in UNIX
• Process terminates by using exit() system call.
• The parent process may wait for termination of a child process by using the
wait()system call. The wait() system call returns status information and the pid
of the terminated child process so that parent can tell which of its children has
terminated
pid = wait(&status);
• If parent terminated without invoking wait , process is an orphan