[man] fork

숭글·2022년 9월 26일
0

fork

#include <unistd.h>

fork() creates a new process by duplicating the calling process.

pid_t fork(void

The new process is referred to as the child process.
The calling process is referred to as the parent process.

The child process and the parent process run in separate memory spaces. At the time of fork() both memory spaces have the same content.

The child process is an exact duplicate of the parent process except for some points -> 😁 check here!

RETURN VALUE
: On success, the PID of the child process is returned in the parent, and 0 is returned in the child.
On failure, -1 is returned in the parent, no child process is created, and errno is set to indicate the error.

Notes

  • The child process is created with a single thread—the one that called fork(). The entire virtual address space of the parent is replicated in the child, including the states of mutexes, condition variables, and other pthreads objects.

  • The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two file descriptors share open file status flags, file offset, and signal-driven I/O attributes.

difference between parent and child

  • The child process has a unique process ID.
  • The child process has a different parent process ID.
  • ...

📖 fork

profile
Hi!😁 I'm Soongle. Welcome to my Velog!!!

0개의 댓글