Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Prof. A. V. Brahmane
Assistant Professor
E-mail : brahmaneanilkumarcomp@sanjivani.org.in
Contact No: 91301 91301 Ext :145, 9922827812
Subject- Operating System and Administration (CO2013)
Unit III- The Structure of Process, Process Control and
Process Scheduling
Content
• Process state and transitions,
• Layout of the system memory,
• Context of the process,
• Saving the context of the process,
• Manipulation the process address space,
• Sleep,
• Process creation,
• Signal,
• Process termination, Awaiting the process termination,
• Invoking other program, Process Scheduling
• Case Study - Access Control, Rootly Powers and Controlling Processes
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Process Control – Scheduling
• The relationship between the system calls and memory management algorithms
is shown in the following diagram:
• Almost all calls use sleep and wakeup so its not shown in the figure. exec also interacts with the
file system algorithms
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Process Creation
• The only way to create a new process in UNIX is to use the fork system call. The
process which calls fork is called the parent process and the newly created
process is called the child process.
• pid = fork();
• On return of the fork system call, the two processes have identical user-level
context except for the value of pid. pid for the parent process is the process ID of
the child process. And pid for child process is 0. The process 0 is the only process
which is not created via fork.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• The steps followed by the kernel for fork are:
• It creates a new entry in the process table.
• It assigns a unique ID to the newly created process.
• It makes a logical copy of the regions of the parent process. If a regions can be
shared, only its reference count is incremented instead of making a physical copy
of the region.
• The reference counts of file table entries and inodes of the process are increased.
• It turned the child process ID to the parent and 0 to the child.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The algorithm fork
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Fork creating a New process context
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Signals
• Signals inform processes of the occurrence of asynchronous events. Processes
may send each other signals with the kill system call, or the kernel may send
signals internally.
• There are 19 signals in the System V (Release 2) UNIX system that can be
classified as follows:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Signal Classifications
• Signals having to do with the termination of a process, send when a process exits or when a process invokes
the signal system call with the death of child parameter.
• Signals having to do with process induced exceptions such as when a process accesses an address outside its
virtual address space, when it attempts to write memory that is read-only (such as program text), or when it
executes a privileged instruction or for various hardware errors.
• Signals having to do with the unrecoverable conditions during a system call, such as running out of system
resources during exec after the original address space has been released
• Signals caused by an unexpected error condition during a system call, such as making a nonexistent system
call (the process passed a system call number that does not correspond to a legal system call), writing a pipe
that has no reader processes, or using an illegal "reference" value for the lseek system call. It would be more
consistent to return an error on such system calls instead of generating a signal, but the use of signals to
abort misbehaving processes is more pragmatic.
• Signals originating from a process in user mode, such as when a process wishes to receive an alarm signal
after a period of time, or when processes send arbitrary signals to each other with the kill system call.
• Signals related to terminal interaction such as when a user hands up a terminal (or the "carrier" signal drops
on such a line for any reason), or when a user presses the "break" or "delete" keys on a terminal keyboard.
• Signals for tracing execution of a process.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Checking and Handling Signals in the Process State Diagram
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The algorithm issig
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Handling Signals
• The handling of signal is done through the algorithm psig,
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Types of Signals
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Process Groups
• The system has to identify processes by "groups" in some cases, for instance, a
signal might relate to all the processes which are ancestors of the login shell. The
kernel uses the process group ID to identify groups of related processes that
should receive a common signal for certain events. It saves the group ID in the
process table.
• The setpgrp system call initializes the process group number of a process and sets
it equal to the value of its process ID.
• grp = setpgrp();
• where grp is the new process group number. A child retains the process group
number of its parent during fork.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Sending Signals from Processes
• Processes use the kill system call to send signals.
• kill (pid, signum);
• where pid identifies the set of processes to receive the signal, and signum is the signal number
being sent. The following list shows the correspondence between values of pid and sets of
processes.
• If pid is a positive integer, the kernel sends the signal to the process with process ID pid.
• If pid is 0, the kernel sends the signal to all processes in the sender's process group.
• If pid is -1, the kernel sends the signal to all processes whose real user ID equals the effective user
ID of the sender (real and effective user IDs are studied later). If the sending process has effective
user ID of superuser, the kernel sends the signal to all processes except processes 0 and 1.
• If pid is a negative integer but not -1, the kernel sends the signal to all processes in the process
group equal to the absolute value of pid.
• In all cases, if the sending process does not have effective user ID of superuser, or its real or
effective user ID do not match the real or effective user ID of the receiving process, kill fails.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Process Termination
• Processes on the UNIX system exit by executing the exit system call. When a
process exits, it enters the zombie state, relinquishes all of its resources, and
dismantles its context except for its process table entry.
• exit (status);
• where status is the exit code returned to the parent. The process may
call exit explicitly, but the startup routine in C calls exit after the main function
returns. The kernel may call exit on receiving an uncaught signal. In such cases,
the value of status is the signal number.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The algorithm for exit
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Awaiting Process Termination
• A process can synchronize its execution with the termination of a child process by
executing the wait system call.
• pid = wait (stat_addr);
• where pid is the process ID of the zombie child, and stat_addr is the address in
user space of an integer that will contain the exit status code of the child.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The algorithm for wait
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Invoking Other Programs
• The exec system call overlays the address space of a process with the contents of
an executable file.
• execve (filename, argv, envp)
• where filename is name of the file being invoked, argv is a pointer to array of
character pointers which are arguments to the program in the executable file,
and envp is a pointer to array of character pointers which are the environment of
the executed program. There are several library functions that call exec,
like execl, execv, execle, and so on. All call execve eventually. The character strings
in the envp array are of the form, "name=value". C programs can access the
environment variables by accessing the global variable environ, initialized by the
C startup routine.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The algorithm for exec
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The User ID of a Process
• There are two user ID associated with a process, the real user ID and the effective
user ID or setuid (set user ID). The real user ID identifies the user who is
responsible for the running process. The effective user ID is used to assign
ownership of newly created files, to check file access permissions, and to check
permission to send signals to processes via the kill system call. The kernel allows a
process to change its effective user ID when it execs a setuid program or when it
invokes the setuid system call explicitly.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• A setuid program is an executable file that has the setuid bit set in its permission
mode field. When a process execs a setuid program, the kernel sets the effective
user ID fields in the process table and u-area to the owner ID of the file. To
distinguish the two fields, let us call the field in the process table the saved user
ID.
• setuid (uid);
• where uid is the new user ID, and its result depends on the current value of the
effective user ID. If the effective user ID of the calling process is superuser, the
kernel resets the real and effective user ID fields in the process table and u-area
to uid. If its not the superuser, the kernel resets the effective user ID in the u-area
to uid if uid has the value of the real user ID or if it has the value of the saved user
ID. Otherwise, the system call returns an error. Generally, a process inherits its
real and effective user IDs from its parent during the fork system call and
maintains their values across exec system calls.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Changing the Size of a Process
• A process can increase or decrease the size of its data region by using
the brk system call.
• brk (endds);
• where endds becomes the value of the highest virtual address of the data region
of the process (called its break value). Alternatively, a user can call
• oldendds = sbrk(increment);
• where increment changes the current break value by the specified number of
bytes, and oldendds is the break value before the call. sbrk is a C library routine
that calls brk. The kernel checks that the new process size is less than the system
maximum and that the new data region does not overlap previously assigned
virtual address space.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Algorithm: brk
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
•Thank you …..
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Unit 3.2 Process Control.ppt (Process Control and Scheduling)

  • 1.
    Sanjivani Rural EducationSociety’s Sanjivani College of Engineering, Kopargaon-423 603 (An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified Department of Computer Engineering (NBA Accredited) Prof. A. V. Brahmane Assistant Professor E-mail : brahmaneanilkumarcomp@sanjivani.org.in Contact No: 91301 91301 Ext :145, 9922827812 Subject- Operating System and Administration (CO2013) Unit III- The Structure of Process, Process Control and Process Scheduling
  • 2.
    Content • Process stateand transitions, • Layout of the system memory, • Context of the process, • Saving the context of the process, • Manipulation the process address space, • Sleep, • Process creation, • Signal, • Process termination, Awaiting the process termination, • Invoking other program, Process Scheduling • Case Study - Access Control, Rootly Powers and Controlling Processes DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 3.
    Process Control –Scheduling • The relationship between the system calls and memory management algorithms is shown in the following diagram: • Almost all calls use sleep and wakeup so its not shown in the figure. exec also interacts with the file system algorithms DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 4.
    Process Creation • Theonly way to create a new process in UNIX is to use the fork system call. The process which calls fork is called the parent process and the newly created process is called the child process. • pid = fork(); • On return of the fork system call, the two processes have identical user-level context except for the value of pid. pid for the parent process is the process ID of the child process. And pid for child process is 0. The process 0 is the only process which is not created via fork. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 5.
    • The stepsfollowed by the kernel for fork are: • It creates a new entry in the process table. • It assigns a unique ID to the newly created process. • It makes a logical copy of the regions of the parent process. If a regions can be shared, only its reference count is incremented instead of making a physical copy of the region. • The reference counts of file table entries and inodes of the process are increased. • It turned the child process ID to the parent and 0 to the child. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 6.
    The algorithm fork DEPARTMENTOF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 7.
    Fork creating aNew process context DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 8.
    Signals • Signals informprocesses of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. • There are 19 signals in the System V (Release 2) UNIX system that can be classified as follows: DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 9.
    Signal Classifications • Signalshaving to do with the termination of a process, send when a process exits or when a process invokes the signal system call with the death of child parameter. • Signals having to do with process induced exceptions such as when a process accesses an address outside its virtual address space, when it attempts to write memory that is read-only (such as program text), or when it executes a privileged instruction or for various hardware errors. • Signals having to do with the unrecoverable conditions during a system call, such as running out of system resources during exec after the original address space has been released • Signals caused by an unexpected error condition during a system call, such as making a nonexistent system call (the process passed a system call number that does not correspond to a legal system call), writing a pipe that has no reader processes, or using an illegal "reference" value for the lseek system call. It would be more consistent to return an error on such system calls instead of generating a signal, but the use of signals to abort misbehaving processes is more pragmatic. • Signals originating from a process in user mode, such as when a process wishes to receive an alarm signal after a period of time, or when processes send arbitrary signals to each other with the kill system call. • Signals related to terminal interaction such as when a user hands up a terminal (or the "carrier" signal drops on such a line for any reason), or when a user presses the "break" or "delete" keys on a terminal keyboard. • Signals for tracing execution of a process. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 10.
    Checking and HandlingSignals in the Process State Diagram DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 11.
    The algorithm issig DEPARTMENTOF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 12.
    Handling Signals • Thehandling of signal is done through the algorithm psig, DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 13.
    Types of Signals DEPARTMENTOF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 14.
    Process Groups • Thesystem has to identify processes by "groups" in some cases, for instance, a signal might relate to all the processes which are ancestors of the login shell. The kernel uses the process group ID to identify groups of related processes that should receive a common signal for certain events. It saves the group ID in the process table. • The setpgrp system call initializes the process group number of a process and sets it equal to the value of its process ID. • grp = setpgrp(); • where grp is the new process group number. A child retains the process group number of its parent during fork. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 15.
    Sending Signals fromProcesses • Processes use the kill system call to send signals. • kill (pid, signum); • where pid identifies the set of processes to receive the signal, and signum is the signal number being sent. The following list shows the correspondence between values of pid and sets of processes. • If pid is a positive integer, the kernel sends the signal to the process with process ID pid. • If pid is 0, the kernel sends the signal to all processes in the sender's process group. • If pid is -1, the kernel sends the signal to all processes whose real user ID equals the effective user ID of the sender (real and effective user IDs are studied later). If the sending process has effective user ID of superuser, the kernel sends the signal to all processes except processes 0 and 1. • If pid is a negative integer but not -1, the kernel sends the signal to all processes in the process group equal to the absolute value of pid. • In all cases, if the sending process does not have effective user ID of superuser, or its real or effective user ID do not match the real or effective user ID of the receiving process, kill fails. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 16.
    Process Termination • Processeson the UNIX system exit by executing the exit system call. When a process exits, it enters the zombie state, relinquishes all of its resources, and dismantles its context except for its process table entry. • exit (status); • where status is the exit code returned to the parent. The process may call exit explicitly, but the startup routine in C calls exit after the main function returns. The kernel may call exit on receiving an uncaught signal. In such cases, the value of status is the signal number. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 17.
    The algorithm forexit DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 18.
    Awaiting Process Termination •A process can synchronize its execution with the termination of a child process by executing the wait system call. • pid = wait (stat_addr); • where pid is the process ID of the zombie child, and stat_addr is the address in user space of an integer that will contain the exit status code of the child. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 19.
    The algorithm forwait DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 20.
    Invoking Other Programs •The exec system call overlays the address space of a process with the contents of an executable file. • execve (filename, argv, envp) • where filename is name of the file being invoked, argv is a pointer to array of character pointers which are arguments to the program in the executable file, and envp is a pointer to array of character pointers which are the environment of the executed program. There are several library functions that call exec, like execl, execv, execle, and so on. All call execve eventually. The character strings in the envp array are of the form, "name=value". C programs can access the environment variables by accessing the global variable environ, initialized by the C startup routine. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 21.
    The algorithm forexec DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 22.
    The User IDof a Process • There are two user ID associated with a process, the real user ID and the effective user ID or setuid (set user ID). The real user ID identifies the user who is responsible for the running process. The effective user ID is used to assign ownership of newly created files, to check file access permissions, and to check permission to send signals to processes via the kill system call. The kernel allows a process to change its effective user ID when it execs a setuid program or when it invokes the setuid system call explicitly. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 23.
    • A setuidprogram is an executable file that has the setuid bit set in its permission mode field. When a process execs a setuid program, the kernel sets the effective user ID fields in the process table and u-area to the owner ID of the file. To distinguish the two fields, let us call the field in the process table the saved user ID. • setuid (uid); • where uid is the new user ID, and its result depends on the current value of the effective user ID. If the effective user ID of the calling process is superuser, the kernel resets the real and effective user ID fields in the process table and u-area to uid. If its not the superuser, the kernel resets the effective user ID in the u-area to uid if uid has the value of the real user ID or if it has the value of the saved user ID. Otherwise, the system call returns an error. Generally, a process inherits its real and effective user IDs from its parent during the fork system call and maintains their values across exec system calls. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 24.
    Changing the Sizeof a Process • A process can increase or decrease the size of its data region by using the brk system call. • brk (endds); • where endds becomes the value of the highest virtual address of the data region of the process (called its break value). Alternatively, a user can call • oldendds = sbrk(increment); • where increment changes the current break value by the specified number of bytes, and oldendds is the break value before the call. sbrk is a C library routine that calls brk. The kernel checks that the new process size is less than the system maximum and that the new data region does not overlap previously assigned virtual address space. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 25.
    Algorithm: brk DEPARTMENT OFCOMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 26.
    •Thank you ….. DEPARTMENTOF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon