Process Management 1-2 Flashcards
What does fork do in a system process?
It creates a copy of itself, creates a new process by trapping OS and making it mostly duplicate
How many times does fork return when called?
Returns twice with each process @ the next instruction)
pid_t fork();
a system wide unique process identifier.
childs pid value is returned in the parent and parents pid is returned in the childs.
What is a forks order of execution?
nondeterministic , parent and child run concurrently.
Post fork, what relation do the parent and child functions have to each other?
They are identical but separate.OS allocates and maintains separate data /state
what if fork fails?
most syscalls will return -1 on failure
What happens to all terminating processes?
They turn into zombies, They become dead but still tracked by OS. -pid remains in use -exit status can be queried
Reaping processes
All processes are responsible for reaping their own immediate children processes
How do you kill a zombie process?
By killing/ terminating the parent process
What happens when the process is orphaned? ( The parent process is killed)
They are adopted by the OS kernel, reaping its children.
Why is it especially important for long running processes to reap their children?
Its important because zombie processes still consume system memory resources. if the parent terminates without reaping the children, then the kernel invokes the init process to reap them
Who reaps the parent?
The shell
what happens when the process is terminated and has more than 1 child?
reaps a zombie child
- returns reaped child’s pid and exit status
info via pointer
what happens when the process has no children when pid_ wait is called?
return -1 immediately populate errno
why are fork and exec separate calls?
They are separate because we might want to tweak the process before running a program in it.
What are task management features?
They allow the shell to run track and manage multiple processes at once
Difference between foreground and background processes?
fg processes: “blocks” additional commands from being run
bg processes can run multiple at once.
what are signals and there aspects?
They are messages delivered by the kernel to user processes.
Aspects of signal processing:
1. sending a signal to a process
2. registering a handler for a given signal
3. delivering a signal (kernel mechanism)
4. designing a signal handler
What happens if a signal is received as its handler is running?
mark it as pending, but don’t run the
handler again! (signal currently blocked)
what happens if a signal is sent many
times before its handler is run?
nothing because we can’t que signals.
what happens if a signal is received as
a handler for a lower priority one is
already running?
we preempt the lower priority handler
(and resume it — if possible — later)
What operations can signals interrupt?
They can interrupt any non atomic operations.
First design goal on signal handlers?
Minimize use of global variables, use mostly primitive data
Second design goal for signal handlers?
prefer separate handlers for different signals.
what is the importance of a signal handler being re-entrant?
It can be called again when already executing.
what are three important lessons to take into consideration for signal handlers?
- Signals can be delivered at any time
- Sometimes Causing it to execute in overlapping fashion with itself when handling multiple signals
- The execution of the sig handlers can overlap , any functions called may have overlapping execution.
What is a direct approach that ensures certain sequence of events cannot be interrupted when there is insidious race condition caused by concurrency?
(can’t predict when child will terminate /
when signal will arrive)
block the signal
What is another instance in which a signal can be blocked?
when the program is forced to call non- reentrant functions from signal handlers.