Professional Documents
Culture Documents
Lab3 Os
Lab3 Os
LAB 3:
Objective: To demonstrate program execution in Linux using various exec() system calls
Lab Tasks:
THEORY
The 'exec( )'
Forking provides a way for an existing process to start a new one, but what about the case where the new process is
not part of the same program as parent process? This is the case in the shell; when a user starts a command it needs to
run in a new process, but it is unrelated to the shell.
This is where the exec system call comes into play. exec will replace the contents of the currently running
process with the information from a program binary. Thus the process the shell follows when launching a
new program is to firstly fork, creating a new process, and then exec (i.e. load into memory and execute) the
program binary it is supposed to run.
2. Execlp:
Execlp function is most commonly used to overlay a process image that has been created by a
call to the fork function.
3. Execle:
The execle function is most commonly used to overlay a process image that has been created by
a call to the fork function.
4. Execv:
OPERATING SYSTEMS
ISMAIL ZAHEER SHEIKH 2020-CE-037 2
Execv(path,argv) causes the current process to abandon the program that it is running and start
running the program in file path.
5. Execvp:
The execvp function is most commonly used to overlay a process image that has been created
by a call to the fork function.
Q2) Write a program that will call another program from child process.
SOURCE CODE 1:
SOURCE CODE 2:
OUTPUT:
OPERATING SYSTEMS
ISMAIL ZAHEER SHEIKH 2020-CE-037 3
Q2) Write a C program to illustrate use of fork() & exec() system call for process creation
Source code 1:
Source Code 2:
OUTPUT:
OPERATING SYSTEMS