You are on page 1of 20

CHAPTER 7 –The

process

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


Phases of process creation
2

1. Fork: Forking creates a process by creating a copy of the existing


process.
 The new process has a different PID, and the process that created it
becomes its parent.
 Parent and child have the same process image.
 If the child doesn’t do an exec, both parent and child continue to
execute the same code from the point forking was invoked.
 Forking creates a process, but it is not enough to run a new program.
 To do that, the forked child needs to overwrite its own image with
the code and data of the new program.
2. Exec. mechanism of overwrite its own image with the code and data
of the new program.
 The child process is said to exec a new program.
 No new process is created here; the PID and PPID of the exec’d
process remain unchanged.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

3. Wait: wait while the child is executing a new program.


 The parent normally waits for the child to die.
 It then picks up the exit status of the child before it does something else.

Example:
 when you run cat from the shell.
 The shell first forks another shell process.
 The newly forked shell then overlays itself with the executable image of cat,
which then starts to run.
 The parent (the original shell) waits for cat to terminate and then picks up
the exit status of the child.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

UID: user id
GID: group id

like HOME and PATH

Inheritance here implies that the child has its own copy of these parameters and
can thus alter the operating environment it has inherited.
This also means that the modified environment is not available to the parent
process.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

x: is local variable
Create new process

export x: make x environmental variable(global variable)

Update the value of x in the child

Will exit the child & back to the parent bash


The parent will not see the updated value of the child

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


Summary
2

• A variable defined in a process is only local to the process and is not


available in a child process.

• When you export the variable, its value is available recursively to all
child processes.

• However, when the child alters the value of the variable, the change is
not seen in the parent.

This should not surprise us since the child works with its own copy of
the environment.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


ps -l: Detailed Process Listing
2

 The ps -l command (ps aux in Linux) provides an informative listing of


processes.
 Apart from the usual attributes that we are familiar with, the command
also displays the state, priority, and size of the process in memory:

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

Didn’t pick up the exit status for zombie.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

If child dies before the parent

 if the parent didn’t pick up (fetch) the exit status of the


child then the child become a zombie.
 The child terminated but its entry is till exist in the process
table. (exit status is not fetched by the parent)

The child entry is removed from the process table.

The child is already terminated but its entry status is still


exist in the process table.

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

init: initiated process

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

Catch

SIGSTOP: ctrl+z If process running in the


SIGKILL: ctrl + c background, you have to use
commands like kill command
CY 371: Linux OS lab Done by: Eng. Walaa Ayyad
2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


2

CY 371: Linux OS lab Done by: Eng. Walaa Ayyad


Thank you all

You might also like