Linux and UNIX Man Pages

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) 							System Calls Manual							   FORK(2)

fork - spawn new process SYNOPSIS
Fork is the only way new processes are created. The new process's core image is a copy of that of the caller of fork. The only distinc- tion is the fact that the value returned in the old (parent) process contains the process ID of the new (child) process, while the value returned in the child is 0. Process ID's range from 1 to 30,000. This process ID is used by wait(2). Files open before the fork are shared, and have a common read-write pointer. In particular, this is the way that standard input and output files are passed and also how pipes are set up. SEE ALSO
wait(2), exec(2) DIAGNOSTICS
Returns -1 and fails to create a process if: there is inadequate swap space, the user is not super-user and has too many processes, or the system's process table is full. Only the super-user can take the last process-table slot. ASSEMBLER
(fork = 2.) sys fork (new process return) (old process return, new process ID in r0) The return locations in the old and new process differ by one word. The C-bit is set in the old process if a new process could not be cre- ated. FORK(2)
Man Page

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