Utkarsh Srivastav
Utkarsh Srivastav

Reputation: 3227

Operating system inside

I have three questions which are causing me a lot of doubts:

  1. If one thread in a program calls fork(), does the new process duplicate all threads, or is the new process single-threaded?

  2. If a thread invokes exec(), will the program specified in the parameter to exec() replace the entire process including ALL the threads?

  3. Are system calls preemptive? For example whether a process can be scheduled in middle of a system call?

Upvotes: 3

Views: 180

Answers (2)

Alexey Frunze
Alexey Frunze

Reputation: 62048

W.r.t. #3: Yes, you can invoke a system call that directly or indirectly makes another thread ready to run. And if that thread has a greater priority than the current and the system is designed to schedule it right then, it can do so.

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477040

For exec, from man execve:

All threads other than the calling thread are destroyed during an execve().

From man fork:

The child process is created with a single thread — the one that called fork().

Upvotes: 4

Related Questions