Assignment 1
Assignment 1
child process id. Child process will display the message “I am Child Process” and the
parentprocess should display “I am Parent Process”.*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// fork() Create a child process
int pid = fork();
if (pid > 0) {
printf("I am Parent process\n");
printf("ID : %d\n\n", getpid());
}
else if (pid == 0) {
printf("I am Child process\n");
// getpid() will return process id of child process
printf("ID: %d\n", getpid());
}
else {
printf("Failed to create child process");
}
return 0;
}
/*Set A-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;
}
else
{ /* Parent Process */
printf("\nParent Process Completed ...");
}
}
return 0;
}