Professional Documents
Culture Documents
(Campus Name)
Practical 2
Dear all,
Kindly complete the following task with your name in output file.
1.Write a Program to display that fork() is working and returning two process id.
Code :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
if(fork()==0)
else
}
int main()
forkexample();
return 0;
Output :
2. Write a program to display "Hello World" with fork() with process id.
Code :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
int p_id,p_pid;
fork();
p_id=getpid();
p_pid=getppid();
return 0;
}
Output :
3. Write a Program to display 1 to 100 numbers. child process print 1-50 and Parent process
should print 51-100.
Code :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void childProcess()
int i;
void parentProcess()
int i;
}
int main()
pid_t pid;
pid = fork();
if (pid == 0)
childProcess();
else
parentProcess();
Output :