#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("
BeforeForking
");
fork();
printf("
After Forking
");
return 0;
}
#include <stdio.h>
#include <unistd.h>
int main()
{
fork();
fork();
fork();
puts("Hi");
return 0;
}
// Output:
// Hi
// Hi
// Hi
// Hi
// Hi
// Hi
// Hi
// Hi
System call fork() is used to create processes. It takes no arguments and
returns a process ID.
The purpose of fork() is to create a new process, which becomes the child
process of the caller.
After a new child process is created, both processes will execute
the next instruction following the fork() system call.
#include <stdio.h>
#include <unistd.h>
int main()
{
fork();
puts("Hi");
return 0;
}
// Output:
// Hi
// Hi
#include <stdio.h>
#include <unistd.h>
int main()
{
fork();
fork();
puts("Hi");
return 0;
}
// Output:
// Hi
// Hi
// Hi
// Hi