0% found this document useful (0 votes)
11 views2 pages

Practical Assignment - Process Set A and B For Class

The document outlines practical assignments for process management in C programming, including creating child processes using fork() and demonstrating the nice() system call to manage process priorities. It also explains the concept of orphan processes and provides sample code for sorting integers using both bubble sort and insertion sort in parent and child processes. Additionally, it includes a task to illustrate orphan processes by terminating the parent before the child completes its execution.

Uploaded by

musalesuman7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Practical Assignment - Process Set A and B For Class

The document outlines practical assignments for process management in C programming, including creating child processes using fork() and demonstrating the nice() system call to manage process priorities. It also explains the concept of orphan processes and provides sample code for sorting integers using both bubble sort and insertion sort in parent and child processes. Additionally, it includes a task to illustrate orphan processes by terminating the parent before the child completes its execution.

Uploaded by

musalesuman7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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()).

You might also like