

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating multiple process using fork() in C
In this section we will see how to use the fork() to make child process in C. We also do some different tasks in each process. So in our parent process we will print different values.
When fork() is called, it returns a value. If the value is greater than 0, then currently it is in parent process, otherwise it is in child process. So using this we can distinguish between the processes.
Example Code
#include <stdio.h> #include <unistd.h> int main() { int n = fork(); //subdivide process if (n > 0) { //when n is not 0, then it is parent process printf("Parent process \n"; } else { //when n is 0, then it is child process printf("Child process \n"); } return 0; }
Output
soumyadeep@soumyadeep-VirtualBox:~$ ./a.out Parent process soumyadeep@soumyadeep-VirtualBox:~$ Child process soumyadeep@soumyadeep-VirtualBox:~$
- Related Questions & Answers
- Creating child process using fork() in Python
- Calculation in parent and child process using fork() in C++
- fork() in C
- Prevent fork bomb by limiting user process in linux
- Creating Linear Gradients using Multiple Color Stops in CSS
- C vs BASH Fork bomb?
- C vs BASH Fork bomb in C/C++?
- Difference between fork() and exec() in C
- fork() to execute processes from bottom to up using wait() in C++
- C program to demonstrate fork() and pipe()
- Creating multiple boxplots on the same graph from a dictionary, using Matplotlib
- The fork() Function in Perl
- Creating multiple Java objects by one type only
- Process Synchronization in C/C++
- Kill Process in C++
Advertisements