Visit Our UNIX and Linux User Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #905
Difficulty: Easy
Generally speaking, Unix systems are commercial, closed source and propriety operating systems so it is expensive to customize for supercomputing projects. Linux, on the other hand, is free and easier to customize.
True or False?
Linux & Unix Commands - Search Man Pages

fork(3f) [bsd man page]

FORK(3F)																  FORK(3F)

fork - create a copy of this process SYNOPSIS
integer function fork() DESCRIPTION
Fork creates a copy of the calling process. The only distinction between the 2 processes is that the value returned to one of them (referred to as the `parent' process) will be the process id of the copy. The copy is usually referred to as the `child' process. The value returned to the `child' process will be zero. All logical units open for writing are flushed before the fork to avoid duplication of the contents of I/O buffers in the external file(s). If the returned value is negative, it indicates an error and will be the negation of the system error code. See perror(3F). A corresponding exec routine has not been provided because there is no satisfactory way to retain open logical units across the exec. How- ever, the usual function of fork/exec can be performed using system(3F). FILES
/usr/lib/libU77.a SEE ALSO
fork(2), wait(3F), kill(3F), system(3F), perror(3F) 4.2 Berkeley Distribution May 27, 1986 FORK(3F)

Check Out this Related Man Page

FORK(2) 						     Linux Programmer's Manual							   FORK(2)

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 dupli- cate 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 exe- cution. 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. SEE ALSO
clone(2), execve(2), vfork(2), wait(2) Linux 1.2.9 1995-06-10 FORK(2)

15 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers


What is a fork? Why would one create a fork? What are the advantages and disadvantages of using a fork? Please advise. Thank You. Deepali (5 Replies)
Discussion started by: Deepali
5 Replies

2. Programming

fork()ing hell!!

Hello I am having serious trouble with the fork command, i basically want to create 9 or 10 child processes and store their pid numbers in array while the children stay resident until i kill() them later , i cannot seem to control how many are made as they all seem to create their own children. ... (16 Replies)
Discussion started by: theultimatechuf
16 Replies

3. Programming


how do differentiate a parent process and child process through the process id while it is executing through fork() command. can i get the process id of both processes and can i do any operation on the process by using process id (6 Replies)
Discussion started by: MKSRaja
6 Replies

4. UNIX for Advanced & Expert Users

Problem due to Fork Error

Hi, I have developed a datastage job...which has many process running in parallel..but because of Fork Error my job is not working:( Can any body help me out to solve this Fork error problem.:rolleyes: My Os is SUNOS. IS there any setting in Unix through admin where in if i set some paramter... (8 Replies)
Discussion started by: Amey Joshi
8 Replies

5. Programming

Question About Multi-Processed Applications... fork()

Assume we have an application built on *nix that uses fork()...then the processes procedure is going to act as follow: X is considered a parent process (first click on application) Y is considered a child process of X (second click on application) Z is considered a child process of Y (third... (6 Replies)
Discussion started by: f.ben.isaac
6 Replies

6. UNIX for Advanced & Expert Users

Fork:resource unavailable

Hello. I have code which create processes with fork(). I set a limit for processes by typing ulimit -u 20. Then I run my code who should create 100 processes. Unfortunately, I have a mistake there and I forgot to quit all of my forked processes when fork gave me return value -1. So I am trapped in... (5 Replies)
Discussion started by: samos
5 Replies

7. Programming

problem implementing fork

Hi, I was honing my linux programming skill when this nuisance started bugging me. I wanted to create an empty file creator program. While creating a large file it must print # for progress bar. But the output shows it happening reverse way. ie. first it copies file and shows the progress... (7 Replies)
Discussion started by: dheerajsuthar
7 Replies

8. UNIX for Advanced & Expert Users

Finding process id of subsequent process

hi all, I am trying to find the process id of the subsequent process created via fork and exec calls in perl. For eg: envVarSetter dataCruncher.exe < input.txt > output.txt When I fork and exec the above command, it returns only the pid of envVarSetter and I don't know how to find the... (9 Replies)
Discussion started by: matrixmadhan
9 Replies

9. Programming

fork and rand()

Hi, I want build 10 processus with fork and that each processus write a value betwen 0 and 9 , but each processus send the same value . So my code ,you can compile and try . #include <time.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> ... (7 Replies)
Discussion started by: carton99
7 Replies

10. Programming

IPC-using fork() in a loop

I need to write a program which creates some n number of processes first and also creates a fifo for each of them, then it connects to the server and.. I tried creating these processes with fork() in a for loop but it doesn't print out what i write inside the child.. for(int count = 0; count... (7 Replies)
Discussion started by: saman_glorious
7 Replies

11. Programming

Fork and then exec problem with signals

Hi All, In my program i am handling SIGHUP signal. In the handler i fork and then exec on child process same binary file which is running. Parent process will die after 10 mins. Now my child process which was exec with same binary file is not receiving SIGHUP signal. Below is the progran code:... (6 Replies)
Discussion started by: sushil_shalin
6 Replies

12. Programming

Parent forking

My question is, how do you fork only the parent processes in unix? For example how would I use the fork function to fork the parent process more than once and leave the children processes alone. This way I do not have children of children. The way I have it set up now it the parent process forks 3... (7 Replies)
Discussion started by: TWhitt24
7 Replies

13. Programming

question about fork

i'm experimenting fork function and i found this code #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <wait.h> #include <fcntl.h> #include <unistd.h> int main(void) { int fd; pid_t p; p = fork(); fork(); if (p>0) { fork();} fork(); fork();... (6 Replies)
Discussion started by: blob84
6 Replies

14. Shell Programming and Scripting

fork processes

Hi, How to count how many processes opened by fork function in perl. Thanks (10 Replies)
Discussion started by: Anjan1
10 Replies

15. Programming

Creating more processes with fork()

Hello people I need help How to make ONE process to create MORE (not one) processes with fork(). I tried several codes but do not work. Thanks (8 Replies)
Discussion started by: nekoj
8 Replies

Featured Tech Videos