Process
Process
•
A link is an association between a filename and an inode.
UNIX has two types of links: hard and symbolic (also called
soft).
Directory entries are called hard links because they directly link
filenames to inodes.
Each inode contains a count of the number of hard links to the
inode.
When a file is created, a new directory entry is created an a new
inode is assigned.
Additional hard links can be created with
ln newname oldname or with the link system call.
A new hard link to an existing file creates a new directory entry
but assigns no other additional disk space.
A new hard link increments the link count in the inode.
A hard link can be removed with the rm command or the unlink
system call.
These decrement the link count.
The inode and associated disk space are freed when the count is
decremented to 0.
Symbolic links or soft links..
•
Programs, Processes and Threads
• A program is a prepared sequence of instructions to
accomplish a defined task.
• A compiler translates the instructions to produce an
executable module.
• When the program is run, the executable module
becomes a program image in main memory.
• A process is an instance of a program that is executing.
• A process has an address space and starts with a single
flow of control.
• The flow of control executes a sequence of
instructions called a thread of execution.
• A thread of execution is a logically related sequence of
instruction addresses assigned to the program counter
during the execution of a program's code.
Process
environ: HOME=/home/stevens\0
PATH=:/bin:/usr/bin\0
SHELL=/bin/sh\0
USER=stevens\0
LOGNAME=stevens\0
NULL
Process image overlay - exec
• Exec is a family of similar functions that do
the following :
• Replace current process image with a new
one
• Do not return if successful
• Same process and pid
• Inherit many properties before exec
• Supports a wide range of functions based
• on execve() system call
exec()
• Executes a file, transforming the calling process into a
new process
• Never return to the calling process
Family of functions for replacing process’s program with the one inside the
exec() call.
int execl( const char *path, const char *arg, ... );
int execlp( const char *file, const char *arg, ... );
(search path)
int execle( const char *path, const char *arg
, ..., char *const envp[] );(manual pass arg)
int execv( const char *path, char *const argv[] );
int execvp( const char *file, char *const argv[] );
int execve( const char *filename, char *const argv [],
char *const envp[] );
exec(..) Family
execv() execvp()
Add envp Convert file to path
execve()
Destroying Processes
• exit() library function
– Terminates and store the status
– Close all open files descriptors
– Only system call that never returns and can’t be
misused
• Process removal
– Releasing the process descriptor of a zombie
process by release_task()
• Kill function
Special Exit Cases
A child exits when its parent is not currently executing
wait()
– the child becomes a zombie
– status data about the child is stored until the parent
does a wait()
• Instruction, user-data, system data are discarded
• But process table slot is maintained in the kernel
A parent exits when 1 or more children are still running
– children are adopted by the system’s initialization process
(/etc/init) -> ppid = 1
• it can then monitor/kill them
Process life cycle
p1 p2 p3 p4 p5
time
0 7 11 16 22
• Shortest Job First (SJF)
– Can be preemptive & non pre-emptive
– Complete the job with shortest next CPU burst
• Round Robin
– A pre-emptive FCFS
– Predefined time quantum which should be large
w.r.t context switch time
• Priority associated with each process
– Can be preemptive & non pre-emptive
– CPU is allotted with process having highest priority
– Problem is Indefinite blocking or starvation
• Multilevel Queue
– partitions the ready queue into several separate queues
based on priority, memory size, process type etc.,
– Scheduling based on individual queue or collectively
• Multilevel feedback Queue
– Process can move between various queues to avoid aging
Process Burst Arrival priority
time time
p1 7 0 5
Waiting Time
p2 4 1 2
p3 5 2 1
p1 23 priority
p2 5
p4 6 3 3 Avg waiting time
p3 0
p5 8 4 4 52 / 5 = 10.1
p4 9
p5 15