hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    What does the fork() command return in a Unix-like operating system?
    Question



    What does the fork() command return in a Unix-like operating system?

    A.

    0 to the child process and a positive value (child’s PID) to the parent process

    B.

    1 to the child process and 0 to the parent process

    C.

    A negative value if the fork fails

    D.

    Both (a) and (c)

    E.

    None of the above

    Correct option is D

    In a Unix-like operating system, the fork() system call is used to create a new process by duplicating the calling process. The return value of fork() is as follows:
    · 0 to the child process: The newly created process receives 0 as its return value from the fork call.
    · A positive value (child's PID) to the parent process: The parent process receives the Process ID (PID) of the child.
    · A negative value if fork fails: If the fork system call fails (e.g., due to insufficient resources), it returns a negative value.
    Thus, the correct answer is (d) Both (a) and (c).
    Important Key Points
    1. fork() Behavior:
    · It creates a new process by duplicating the calling process.
    · The child process is an almost identical copy of the parent, except for its PID and return value from fork().
    2. Return Values:
    · 0: Returned to the child process.
    · Positive value (child’s PID): Returned to the parent process.
    · Negative value: Indicates fork failure, such as when the system is out of process table entries or memory.
    3. Practical Use: fork() is often used in multitasking and multiprocessing to spawn new processes.
    Knowledge Booster
    · How fork() works:
    · The child process gets its own copy of the parent’s memory, including stack and heap.
    · Both processes continue executing from the instruction after the fork() call.
    · Example Code:

    Output:
    · Parent process: "This is the parent process, child PID: <child_pid>".
    · Child process: "This is the child process".
    Common Issues with fork():
    · Overuse of fork() can lead to fork bomb, a situation where too many processes exhaust system resources.
    · fork() doesn't return to the child or parent in the same way in modern threading environments (use pthread or exec() family functions for more control).

    Free Tests

    Free
    Must Attempt

    RBI Asst Prelims 2026: Quant Advance level Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    RBI Asst Prelims 2026: Reasoning Advance level Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    NABARD Development Assistant Mains 2026 Full Mock Test -01

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon105 Mins
    languageIcon English

    Similar Questions

    test-prime-package

    Access ‘IBPS SO IT Officer’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    382k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow