Lab 3 Processes
Lab 3 Processes
Lab 3 Processes
Processes
1. Looking at Processes
1.1 Process IDs
Each process in a Linux system is identified by its unique process ID, referred to as pid.
Process IDs are 1- 32768 numbers that are assigned sequentially by Linux as new process
are created.
Every process also has a parent process (except init). Thus, we can think the processes in
the Linux are arranged in a tree, with the init process at its root. The parent process ID, or
ppid, is simply the process ID of the process's parent.
Most of the process manipulation functions are declared in the header file <unistd.h>. A
program can obtain the process ID of the process it's running with the getpid() system
call, and it can obtain the process ID of its parent process with the getppid() system call.
1
2 Creating a processes
Using fork
When programs calls fork, the parent process continues executing the program from the
point that fork was called. The child process, too, executes the same process from the
same place. The fork return some value for its parent and the child process always has 0
pid.
2
Ex. 3.4: Using fork
#include < stdio.h>
#include <unistd.h>
int main()
{
int pid;
printf(“The main program process ID is %d \n”, (int) getpid());
pid = fork();
if (pid != 0){
printf(“This is the parent process, with id % d \n”, (int) getpid());
printf(“The child process ID is %d \n”, pid);
}
else
printf(“ This is the child process, with id %d\n”, (int) getpid());
return 0;
}
Assignment #L3
1. Execute each of the programs (given in Ex. 3.1 – 3.4) at lest three times, and
analyze their outputs.
4. Write the program that creates the the four process using fork() system call.