195k views
5 votes
What type of values does the Unix system call fork() return?

User Ehrencrona
by
6.9k points

1 Answer

5 votes

Final answer:

The Unix system call fork() returns different values for the parent process and the child process.

Step-by-step explanation:

The Unix system call fork() is used to create a new process by duplicating the existing process. It returns different values for the parent process and the newly created child process. The parent process receives the process ID (PID) of the child process, whereas the child process receives a value of 0.

For example, if we consider the following code:

pid_t pid = fork();
if (pid == 0) {
// child process
} else if (pid > 0) {
// parent process
}

The value of pid will be 0 in the child process, and greater than 0 (the child's process ID) in the parent process.

User Cduhn
by
7.5k points