473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

fork( ) function

9
I have red hat linux on my pc. I am new to linux. Can any one please tell me how fork( ) function works & what is its application.
Nov 21 '06 #1
1 5597
sashi
1,754 Expert 1GB
I have red hat linux on my pc. I am new to linux. Can any one please tell me how fork( ) function works & what is its application.
Hi there,

Kindly refer to below article for further reading & understanding, hope it helps. Good luck & take care.

NAME
fork - create a child process

SYNOPSIS
#include <sys/types.h>
#include <unistd.h>

pid_t fork(void);
DESCRIPTION
fork creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.

Under Linux, fork is implemented using copy-on-write pages, so the only penalty incurred by fork is the time and memory required to duplicate the parent's page tables, and to create a unique task structure for the child.
RETURN VALUE
On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and errno will be set appropriately.
ERRORS

EAGAIN
fork cannot allocate sufficient memory to copy the parent's page tables and allocate a task structure for the child.
ENOMEM
fork failed to allocate the necessary kernel structures because memory is tight.

CONFORMING TO
The fork call conforms to SVr4, SVID, POSIX, X/OPEN, BSD 4.3.
Nov 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: mishra | last post by:
Hi, i thied the following code.. # include<stdio.h> int main() { int a; printf("Hello..."); a=fork(); printf("hi\n"); return(0);
11
by: ramu | last post by:
Hi All, We know that a c function never returns more than one value. Then how come the fork() function returns two values? How it is implemented? Regards
3
by: bite me if you can... | last post by:
The man page of fork() says that the file descriptor are shared by parent process & childern processes, so any operation of file descriptor will affect them both. But why the behavior of FILE...
1
by: vasu1308 | last post by:
Hi all, I want know about writing a program that spwans 3 child processes using fork() function call. Thanks in advance Vasu
5
by: vsowmya | last post by:
Hi I have to develop a c program to create a parent process that spawn three child process. i have written a code but that was not working out.Please help me in getting the desired output of my...
5
by: JoeW | last post by:
Now before I go into detail I just want to say that this is purely for my own benefit and has no real world usage. I remember way back when the tool for *nix systems called forkbomb was created. I...
3
by: manjuscripts | last post by:
The output of the below program is "hihi" as "hi" is printed by both parent and child process #include<stdio.h> main() { printf("hi"); fork(); }
4
by: AK | last post by:
Hi everyone, Please check out this query that I have in : http://groups.google.com/group/progav/browse_thread/thread/29057ec587dd46b3 (its a bit long, thats why I am not typing it again;...
1
by: che wan | last post by:
#include<stdio.h> #include<math.h> int a; int b; int c; int i,j,m,n,p,q; void main() {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.