Reputation: 3227
I have three questions which are causing me a lot of doubts:
If one thread in a program calls fork()
, does the new process
duplicate all threads, or is the new process single-threaded?
If a thread invokes exec()
, will the program specified in the parameter
to exec()
replace the entire process including ALL the threads?
Are system calls preemptive? For example whether a process can be scheduled in middle of a system call?
Upvotes: 3
Views: 180
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
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