Process Creation ad Termination - Introduction to Operating System - Lecture Notes, Study notes of Operating Systems

Process creation, Process management in UNIX, Sample codes, Process termination, Process managemant in Linux, System calls, Operations in processes, Process tree. Above mentioned are key points of this lecture handout. Virtual University handout for introduction to operating system are in detail and explanatory.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
pf3
pf4

Partial preview of the text

Download Process Creation ad Termination - Introduction to Operating System - Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems--- [CS-604] 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

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:
  3. The child process is a duplicate of the parent process.
  4. 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.

creates an exact memory image of the parent process and returns 0 to the child process and the process ID of the child process to the parent process.

Figure 6.3 Semantics of the fork system call

After the fork() system call the parent and the child share the following: ƒ Environment ƒ Open file descriptor table ƒ Signal handling settings ƒ Nice value ƒ Current working directory ƒ Root directory ƒ File mode creation mask (umask) The following things are different in the parent and the child: ƒ Different process ID (PID) ƒ Different parent process ID (PPID) ƒ Child has its own copy of parent’s file descriptors The fork() system may fail due to a number of reasons. One reason maybe that the maximum number of processes allowed to execute under one user has exceeded, another could be that the maximum number of processes allowed on the system has exceeded. Yet another reason could be that there is not enough swap space.

Kernel Space

Parent Process

Child Process pid = 0

pid = 1234pid = 12345

pid = 0