Skip to the content.

Process Control

Process Creation

A Process is created in many ways which include

The return type of fork is a pid_t (process number)

pid_t fork();

Here the pid value is different in parent and child processes

picture 1

we can see code3() is working in only child and code4() is working only in forked child process

exit()

#include <stdlib.h>
int main(){
    exit(EXIT_SUCCESS); /* or return EXIT_SUCCESS */
}

pid_t wait(int *stat_loc)

#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
 
int main(){
    if (fork()== 0)
        printf("part1");
    else{
        printf("part2\n");
        wait(NULL);
        printf("part3");
    }
    return 0;
}

in this code part1 and part2 may print in any fashion but part3 must be printed after part1 only as wait will wait till completion of child process

kill()

Process Sheduling Stratagies

FCFS

SPN

SRT

Round Robin

HRRN

Fair Share Sheduling