Practical Assignment – Process Management
Set A
1) Implement the C Program to create a child process using fork(), display parent and child
process id. Child process will display the message “I am Child Process” and the parent
process should display “I am Parent Process”.
2) Write a program that demonstrates the use of nice() system call. After a child process is
started using fork(), assign higher priority to the child using nice() system call.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if (pid == 0)
{
printf("\nI am child process, id=%d\n",getpid());
printf("\nPriority :%d,id=%d\n",nice (-7),getpid());
}
else
{
printf("\nI am parent process, id=%d\n",getpid());
nice(1);
printf("\nPriority :%d,id=%d\n",nice (15),getpid());
}
return 0;
}
Explaination :
nice() System Call:
Using nice() system call, we can change the priority of the process in multi-tasking
system. The new priority number is added to the already existing value.
int nice(int inc);
nice() adds inc to the nice value. A higher nice value means a lower priority. The range of the
nice value is +19 (low priority) to -20 (high priority).
Orphan process :
The child processes whose parent process has completed execution or terminated are
called orphan process. Usually, a parent process waits for its child to terminate or finish their
job
and report to it after execution but if parent fails to do so its child results in the Orphan
process. In most cases, the Orphan process is immediately adopted by the init process (a very
first process of the system).
Set B
1) Implement the C program to accept n integers to be sorted. Main function creates child
process using fork system call. Parent process sorts the integers using bubble sort and
waits for child process using wait system call. Child process sorts the integers using
insertion sort.
2) Write a C program to illustrate the concept of orphan process. Parent process creates a
child and terminates before child has finished its task. So child process becomes orphan
process. (Use fork(), sleep(), getpid(), getppid(), kill()).