process creation

21
Process Creation in UNIX Presentation by K.Gautam Presentation by K.Gautam Presented by Presented by K.Gautam and Ashok K.Gautam and Ashok

Upload: gautam-kumar

Post on 29-Jun-2015

1.064 views

Category:

Business


2 download

TRANSCRIPT

Page 1: Process creation

Process Creation in UNIX

Presentation by K.GautamPresentation by K.Gautam

Presented by Presented by K.Gautam and Ashok K.Gautam and Ashok

Page 2: Process creation

Creation of a Process

fork system call. Invoker is Parent and Invokee is Child pid = fork();

Page 3: Process creation

Return from fork()

The two processes have identical copies of their user-level context

In the parent process, pid is the child process ID;

in the child process, pid is 0.

Page 4: Process creation

Process 0

created internally by the kernel when the system is booted,

is the only process not created via fork.

Page 5: Process creation

The kernel operations for fork.

1)It allocates a slot in the process table for the new process.

2)It assigns a unique ID number to the child process.

3)It makes a logical copy of the context of the parent process. .

4)It increments file and inode table counters for files associated with the process.

5)It returns the ID number of the child to the parent process, and a 0 value to the child process.

Page 6: Process creation

ALGORITHM

Page 7: Process creation

algorithm fork

input: none output: to parent process, child PID number to

child process, 0 {

check for available kernel resources; get free proc table slot, unique PID number; check that user not running too many

processes; mark child state "being created;"

Page 8: Process creation

algorithm fork

copy data from parent proc table slot to new child slot; increment counts on current directory inode and

changed root (if applicable); increment open file counts in file table; make copy of parent context (u area, text, data, stack)

in memory;

Page 9: Process creation

algorithm fork

push dummy system level context layer onto child system level context;

dummy context contains data allowing child process to recognize itself, and start running from here when scheduled;

Page 10: Process creation

algorithm fork

if (executing process is parent process)

{

change child state to "ready to run;" return (child ID); /* from system to user */

}

else /* executing process is the child process */

{

initialize u area timing fields; return @); /• to user •/

}

}

Page 11: Process creation
Page 12: Process creation

Checks before forking

Resources to complete the fork successfully.

On a swapping system,

it needs space either in memory or on disk to hold the child process;

on a paging system,

it has to allocate memory for auxiliary tables such as page tables.

If the resources are unavailable,

the fork call fails.

Page 13: Process creation

Checks continued....

The kernel finds a slot in the process table

to start constructing the context of the child process User does not have too many processes running

It also picks a unique ID number for the new process,

one greater than the most recently assigned ID

Page 14: Process creation

Process Limits

(configurable) limit on the number of processes a user can simultaneously execute

Ordinary users cannot create a process that would occupy the last remaining slot in the process table,

Because this could cause a deadlock

Page 15: Process creation

Super user Limits

A superuser can execute as many processes as it likes, bounded by the

size of the process table,

superuser process can occupy the last available slot in the process table

Page 16: Process creation

Inheritance

Various fields are copied from the parent to the child

the child "inherits" the parent process real and effective user ID numbers

the parent process group, the child process resides in the current directory

of the parent process the child process inherits the chroot changes and

increments its inode reference count Access rights to files opened by parent

Page 17: Process creation

user-level context of the child process

It allocates memory for the child process u area, regions, auxiliary page tables,

duplicates every region in the parent process using algorithm dupreg

and attaches every region to the child process using algorithm attachreg

Page 18: Process creation

Dynamic portion The kernel copies the parent context layer 1,

containing the user saved register context the kernel stack frame

The kernel then creates a dummycontext layer(2)

containing the saved register context for context layer (1)

It sets the program counter and other registers in the saved register context so it can be restored even though it has never been executed

Page 19: Process creation

Child process is ready !!

When the child context is ready, The parent completes its part of fork by

Child state to "ready to run (in memory)" Returning the child process ID to the user

The child process appears to have awakened after awaiting a resource

Page 20: Process creation

Any Questions ?

Page 21: Process creation

Thank You !!