Process Creation And Termination-Operating Systems-Lecture Notes, Study notes for Operating System. Cochin University of Science and Technology

Operating System

Description: Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: Operating, Process, System, Creation, Operations, Managment, Linux, Unix, Execution, Children, Dynamically
Showing pages  1  -  2  of  4
35
Operating [CS-604]Systems Lecture No. 6
Operating Systems
Lecture No. 6
Reading Material
Operating Systems Concepts, Chapter 4
UNIX/Linux manual pages for the fork()system call
Summary
Process creation and termination
Process management in UNIX/Linux— system calls: fork, exec, wait, exit
Sample codes
Operations on Processes
The processes in the system execute concurrently and they must be created and deleted
dynamically thus the operating system must provide the mechanism for the creation and
deletion of processes.
Process Creation
A process may create several new processes via a create-process system call during the
course of its execution. The creating process is called a parent process while the new
processes are called the children of that process. Each of these new processes may in
turn create other processes, forming a tree of processes. Figure 6.1 shows partially the
process tree in a UNIX/Linux system.
Figure 6.1 Process tree in UNIX/Linux
In general, a process will need certain resources (such as CPU time, memory files,
I/O devices) to accomplish its task. When a process creates a sub process, also known as
a child, that sub process may be able to obtain its resources directly from the operating
system or may be constrained to a subset of the resources of the parent process. The
parent may have to partition its resources among several of its children. Restricting a
docsity.com
36
process to a subset of the parent’s resources prevents a process from overloading the
system by creating too many sub processes.
When a process is created it obtains in addition to various physical and logical
resources, initialization data that may be passed along from the parent process to the child
process. When a process creates a new process, two possibilities exist in terms of
execution:
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 possibilities in terms of the address space of the new process:
1. The child process is a duplicate of the parent process.
2. The child process has a program loaded into it.
In order to consider these different implementations let us consider the UNIX
operating system. In UNIX its process identifier identifies a process, which is a unique
integer. A new process is created by the fork system call. The new process consists of a
copy of the address space of the parent. This mechanism allows the parent process to
communicate easily with the child process. Both processes continue execution at the
instruction after the fork call, with one difference, the return code for the fork system
call is zero for the child process, while the process identifier of the child is returned to the
parent process.
Typically the execlp system call is used after a fork system call by one of the
two processes to replace the process’ memory space with a new program. The execlp
system call loads a binary file in memory –destroying the memory image of the program
containing the execlp system call.—and starts its execution. In this manner, the two
processes are able to communicate and then go their separate ways. 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 termination of the child.
The parent waits for the child process to terminate, and then it resumes from the call to
wait where it completes using the exit system call.
Process termination
A process terminates when it finishes executing its final statement and asks the operating
system to delete it by calling the exit system call. At that point, the process may return
data to its parent process (via the wait system call). All the resources of the process
including physical and virtual memory, open the files and I/O buffers – are de allocated
by the operating system.
Termination occurs under additional circumstances. A process can cause the
termination of another via an appropriate system call (such as abort). Usually only the
parent of the process that is to be terminated can invoke this system call. Therefore
parents need to know the identities of its children, and thus when one process creates
another process, the identity of the newly created process is passed to the parent.
A parent may terminate the execution of one of its children for a variety of reasons,
such as:
The child has exceeded its usage of some of the resources that it has been
allocated. This requires the parent to have a mechanism to inspect the state of its
children.
The task assigned to the child is no longer required.
docsity.com
The preview of this document ends here! Please or to read the full document or to download it.
Document information
Uploaded by: sarang
Views: 1342
Downloads : 0
University: Cochin University of Science and Technology
Upload date: 06/08/2012
Embed this document:
Docsity is not optimized for the browser you're using. In order to have a better experience please switch to Google Chrome, Firefox, Internet Explorer 9+ or Safari! Download Google Chrome