The objectives of these slides are -
- To introduce the notion of a process - a program in execution, which forms the basis of all computation
- To describe the various features of processes, including scheduling, creation and termination, and communication
- To explore interprocess communication using shared memory and message passing
3. 3
Operation on Procesess
Process Creation
Process Termination
Interprocess Communication
4. 4
Operation on Processes
Process executes concurrently
They are created and deleted dynamically, so
System must provide mechanisms for:
process creation
process termination
One process may create several process via system call during its
execution
5. 5
• Creating process is called a parent process, and the new processes
are called the children of that process
• Parent process create children processes, which, in turn create
other processes, forming a tree of processes
• Generally, process identified and managed via a unique process
identifier (pid)
- an integer value
- used as an index to access various attributes of a process within the kernel
5
7. 7
• init process - serves as the root parent process for all user processes
• kthreadd process - responsible for creating additional processes that
perform tasks on behalf of the kernel
• sshd process - responsible for managing clients that connect to the
system by using SSH protocol
• login process - responsible for managing clients that directly log onto
the system
• listing of processes by using the ps command
• Recursively tracing parent processes
7
command: ps -el
8. 8
• Resource sharing options
• Resources such as CPU time, files, memory , I/O devices are used
by process
• When sub process are created how the resources are used
• Parent and children share all resources
• Children share subset of parent’s resources- memory,files
• Parent and child share no resources- child get resources directly
form OS
• Execution Options
• Parent process is also responsible for initialization of data
• Passed to child process contents of files (like img.jpg) and
terminal details
• Example, consider a process whose function is to display the contents
of a file —say, image.jpg—on the screen of a terminal
8
9. 9
• When a process creates a new process, two possibilities for
execution exist:
1. The parent continues to execute concurrently with its children
2. The parent waits until some or all of its children have
terminated
• There are also two address-space possibilities for the new
process:
1. The child process is a duplicate of the parent process
2. The child process has a new program loaded into it
• To understand difference between children and parent processes -
understand the concept of creating a process in an UNIX
operating system
10. 10
10
/* Creating a separate process using the UNIX fork() system call */
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0)
execlp("/bin/ls","ls",NULL);
{ /* child process */
}
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
}
return 0;
}
11. 11
• UNIX examples
• fork() - system call creates new process
• exec() - system call used after a fork() to replace the process’
memory space with a new program
• wait() - parent wait till child complete if it has nothing to do, move
from ready queue
• exit() - when child use, parent resume from wait state
11
12. 12
• Why parent process state will be in wait() until child
terminates?
• Because of exec() system call
12
13. 13
• Process executes last statement and then asks the operating system
to delete it using the exit() system call.
• Returns status data from child to parent (via wait())
• Process’ resources are deallocated by operating system
• Parent may terminate the execution of children processes using the
abort() system call. Some reasons for doing so:
• Child has exceeded 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
13
14. 14
• Some operating systems do not allow child to exists if its parent
has terminated. If a process terminates, then all its children must
also be terminated.
• cascading termination. All children, grandchildren, etc. are
terminated.
• The termination is initiated by the operating system.
• Process can also terminated by using the exit() system call
• The parent process may wait for termination of a child process by
using the wait()system call. The call returns status information and
the pid of the terminated process
pid = wait(&status);
14
15. 15
• If no parent waiting (did not invoke wait()) process is a zombie
• A zombie process is a process whose execution is completed
but it still has an entry in the process table. Zombie
processes usually occur for child processes, as the
parent process still needs to read its child's exit status.
• If parent terminated without invoking wait , process is an orphan
• A process whose parent process no more exists i.e. either
finished or terminated without waiting for its child process to
terminate
16. 16
16
Multiprocess Architecture – Chrome Browser
• Many web browsers ran as single process (some still do)
• If one web site causes trouble, entire browser can hang or crash
Google Chrome Browser is multiprocess with 3 different types of processes:
• Browser process manages user interface, disk and network I/O
• Renderer process renders web pages, deals with HTML, Javascript. A new
renderer created for each website opened
• Runs in sandbox restricting disk and network I/O, minimizing effect of
security exploits
• Plug-in process for each type of plug-in
17. 17
Interprocess Communication
• Processes within a system may be independent or cooperating
• Independent process does not affect and does not get affected by other
process, they don’t share data
• Cooperating process can affect or be affected by other processes,
including sharing data
• Reasons and Advantages of process cooperation
• Information sharing - allow concurrent access of shared files
• Computation speedup - execution of process in parallel fashion
• Modularity - construct the system in a modular fashion
• Convenience - compilation of files in parallel
18. 18
Interprocess Communication
• Cooperating processes need
interprocess communication
(IPC)
• Two models of IPC
• Shared memory
• Message passing
fig: Communications models. (a) Message passing. (b)
Shared memory