Unit5 Unix Half
Unit5 Unix Half
- A process is defined as a program in execution. Each process has a unique identification number
(PID) allocated to the process by the kernel.
- If process, considered as a tuple, the attributes can be as follows:
Forking:
- First phase in the creation of a process. fork() command is used to create separate, duplicate
process.
- Parent process makes the call to the system by using fork () command, which makes the exact
copy if itself.
- The copy will be of the memory of the calling process at the time of the fork () system call.
- after the fork () there will be two processes with identical memory images.
- Each one of these two processes has to return from the fork () system call. Thus, there will be
two return values.
Example:
Int main ()
{ fork();
echo hi }
Output: Hi Hi // first Hi belongs to parent process & second Hi belongs to the child process.
Example:
main
{
fork();
fork();
echo hi
Example:
main
{
fork();
fork();
fork()
echo hi
- Second phase in creation of the process. Exec() command is used to replace the entire
process.
- This system call simply overwrites the text and data area of the child process.
- This process does the overwriting by using the text and the data of another program and then
starts executing the process.
exec() has 2 arguments:
o File / program
o Arguments of the file / program
- exec() system call has the following family functions
o cl
▪ Syntax:
Int execl (path of the file /file, arguments, …);
o clp
▪ Syntax:
Int execlp (path of the file /file, arguments, …);
o cle
▪ Syntax:
Int execle (path of the file /file, arguments, envp[] files);
o cv
▪ Syntax:
Int execv (path of the file /file, arguments, …);
o cvp
▪ Syntax:
Int execvp (path of the file /file, arguments, …);
o cvpe
▪ Syntax:
Int execvpe (path of the file /file, arguments, envp[] files);
Example
Output:
- At the end of the overlaying and execution, a call is made to the exit () function that terminates
the child process and sends a signal back to the parent process.
Fork () Exec ()
Syntax:
$ps [options]
Example:
$ps
Option Description
SIGNALS
A signal is a message sent to a program under execution, that is a process, on one of the following two
occasions.
Signals are identified by integers. “info kill” command can be used to see the full list of the SIGNAL
names. Some main names can be shown below.