
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
fork() in C
In this section we will see what is the fork system call in C. This fork system call is used to create a new process. This newly created process is known as child process. The current process which is creating another child process is called the parent process.
A child process uses the same program counter, CPU register, same files that are used by the parent process.
The fork() does not take any parameter, it returns integer values. It may return three types of integer values.
Negative Number: It returns negative number when child process creation is failed
Zero Value: It returns Zero for the newly created child process
Positive Value: The positive value is returned to the parent process.
Example Code
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { fork(); //make a child process of same type printf("Fork testing code
"); return 0; }
Output
soumyadeep@soumyadeep-VirtualBox:~$ ./a.out Fork testing code soumyadeep@soumyadeep-VirtualBox:~$ Fork testing code soumyadeep@soumyadeep-VirtualBox:~$
- Related Articles
- C vs BASH Fork bomb in C/C++?
- C vs BASH Fork bomb?
- Difference between fork() and exec() in C
- Creating multiple process using fork() in C
- C program to demonstrate fork() and pipe()
- Calculation in parent and child process using fork() in C++
- The fork() Function in Perl
- Preventing Bash Fork Bombs in Linux
- fork() to execute processes from bottom to up using wait() in C++
- Creating child process using fork() in Python
- Difference Between fork() and vfork()
- Prevent fork bomb by limiting user process in linux
- What is Fork Bomb, aka Rabbit Virus?
- How does a tuning fork make a sound?
- Name the type of waves produced when a tuning fork is struck in air.

Advertisements