What happens immediately after a fork() system call in a Unix-like operating system?
Think about whether the parent process continues to run after fork().
After fork(), the operating system creates a new child process that is an exact copy of the parent process. Both processes continue running independently.
What is the primary purpose of the exec() family of system calls in process creation?
Consider what happens to the program code when exec() is called.
The exec() system call replaces the current process's code and data with a new program, without creating a new process.
Consider the following code snippet in a Unix-like system:
pid = fork()
if pid == 0:
exec("/bin/ls")
else:
wait()What is the expected behavior of this code?
Remember what fork() returns in parent and child, and what exec() does.
The child process replaces its code with /bin/ls and runs it. The parent waits for the child to finish before continuing.
Which statement best describes the difference between fork() and exec() system calls?
Think about whether each call creates a new process or changes the current one.
fork() duplicates the current process creating a child; exec() replaces the current process's code with a new program.
Why do most Unix-like programs use fork() followed by exec() to run a new program instead of just calling exec() directly?
Consider what happens if exec() is called without fork().
Calling exec() replaces the current program, so fork() is used first to create a new process that runs the new program, allowing the original to continue.