Reputation: 45
I’m writing a program that simulates an unix-based operating system and I have some questions:
The wait() function will suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process
2.When the process is in the waiting state, it doesn't execute its code until for example the status information for one of the terminated child processes is available, is that right? So it can't for example call a fork fuction while waiting, is that correct?
3.Are there any restriction on when a process can normally be killed in UNIX?
3.a. Are users authorized to kill root processes? (all of the root processes at will?)
Upvotes: 2
Views: 2628
Reputation: 753525
It is indeterminate whether B or C will be reported first.
While the process is in wait()
, it can do nothing else (in a single-threaded process).
No restrictions for the most part. There are non-interruptible system calls, but the system tries to avoid getting processes hung in them.
No; a user can kill their own processes. User root
can kill other people's process (in general); but no-one else can kill root
's processes.
Upvotes: 0
Reputation: 249123
wait()
returns the PID of whatever child process exited. If two have exited, you must call wait()
twice and check the returned PIDs. You shouldn't rely on the order.wait()
(without the WNOHANG
option) is to block. So you cannot do anything else, apart from handling signals, in the waiting process.Upvotes: 2