Systems Programming Exam 2
Processes must be _________________________________ from getting to use the CPU
"swapped" in and out
What does the fork() system call return?
-1 if unsuccessful, 0 in the child, child PID in the parent
What do exec functions return?
-1 on error, nothing on success
Swapper and Sched have a PID of
0, as part of the kernel, a system process responsible for memory management
Init has a PID of
1
How long does a context switch typically take?
1 μsec
What is a job scheduler?
A long term scheduler that selects which processes to be brought in the ready queue and controls degree of multiprogramming.
What is a program?
A passive set of instructions stored in memory.
What is the CPU scheduler?
A short term scheduler that selects which processes should be executed next and allocates the CPU
Intuitively, a process is the ____________ of a physical processor.
Abstraction
Running
Actively executing instructions on the CPU
What is a Program Counter?
Address of next instruction to be executed (may be in kernel or user memory space of this process.)
What is the created state?
Also "new", initial state when created
What is the waiting state?
Also "ready", awaiting to be scheduled for execution
I/O buffering affects __________________.
Amount of output shown
What is a process?
An active execution of a program stored in memory.
What resources does a process need to accomplish its task?
CPU time, memory, files, I/O devices.
What is the accounting information in a PCB?
CPU used, clock time elapsed since start, time limits
What does wait() do
Causes the parent process to pause until the first child terminates.
What is the user level context?
Code, data, stack, heap
What is data in memory?
Contains global and static variables initialized at runtime.
What is stack in memory?
Contains return addresses, function parameters, and variables.
What is text in memory?
Contains the actual program code or executable instructions.
What is heap in memory?
Contains the dynamic memory allocated at runtime.
Processor Status Register
Contains the hardware status at the time of preemption contents and format are hardware dependent.
What is a CPU register in terms of the PCB?
Contents of all process-centric registers
What are the states in a process state machine?
Created, waiting, running, blocked, terminated
What do exec function accept?
Either a path name or an argument.
How frequently is the CPU Scheduler invoked?
Every few milliseconds
How often is the job scheduler invoked?
Every few seconds to every few minutes
To run a process correctly, the process instructions must be ________________.
Executed within the process context
What does the parent do after the fork request arrives?
Goes back to waiting for the next service request to arrive
General-Purpose Registers
Hardware dependent, R0, R1, R2
What is the I/O Status information?
I/O devices allocated to process, list of open files
The two main reasons for the fork() system call are....
If there are already too many processes in the system (which usually means something else is wrong), OR if the total number of processes for this real user ID exceeds the system's limit
How does fork() work?
It creates a child process by making an exact copy of the parent process and then starts the process concurrently.
What is a process control block table?
It is a table within the OS that contains one entry for each process.
What are the queues of processes maintained by the job scheduler?
Job queue, ready queue, device queues.
What is the program counter?
Location of instruction to execute next
The more complex the OS and the PCB, the __________ the context switch
Longer
What is the memory management information
Memory allocated to the process
When a process wants to duplicate itself so that the parent and child can each execute different sections of code at the same time. This is most common for _______________.
Network servers - the parent waits for a service request from a client
Terminated
No longer running due to completion or being killed
Output interleaving is __________________, meaning ____________________
Nondeterministic, cannot determine exact output by looking at code.
What else is needed in a process context?
OS resources such as open files, signal related data structures, etc.
Does the user level context contain all the states necessary to run a program?
Only if the system runs through one program at a time.
When a program is loaded into memory, it is _____________.
Organized into text, data, heap, and stack.
What does the process control block contain?
Other information that the OS needs to manage the process such as status and priority
What elements can uniquely identify the process?
PID, State, Priority, Program counter, memory pointers, context data, I/O status information, accounting information
A ___________ process creates a _________ process, which _______________, forming a ______________.
Parent, child, create other processes, tree of processes
Stack Pointer (SP)
Points to the top of the kernel or user stack, depending on the mode of operation at the time of preemption
What is the CPU scheduling information?
Priorities, scheduling queue pointers
Registers should be a part of ___________________. The is called Register Context.
Process Context.
Other context information is stored in a data structure called ________________.
Process control block
What activities is the OS responsible for?
Process creation and deletion, Process suspension and resumption, Provision of mechanisms for Process synchronization and Process communication, and Deadlock handling
What does the task control block contain?
Process state, Program counter, CPU registers, CPU scheduling information, Memory management information, I/O status information
In process scheduling...
Processes migrate among the various queues
____________ becomes __________ when loaded into memory.
Programs, Processes
Register context
Registers, such as R0, R1, ...., PC, SP, etc.
Once the child process has terminated, the parent process _______________.
Resumes execution
What does wait() and waitpid() return?
Return the PID of the terminated process if successful and or -1 if not.
When CPU switches to another process, the OS must
Save the PCB of the old process being swapped out, select the new process to be swapped in, and load the PCB of the new process being swapped in
The execution of a process must progress in a ________________ fashion.
Sequential
What is the job queue?
Set of all PCSs in the system
What are the device queues?
Set of processes waiting for an I/O device
When a process wants to execute a different program. This is most common for ________
Shells
CPU-Count process
Spends more time doing computations, few very long CPU bursts.
The high address is the _________.
Stack
Init is replaced by __________ in many Linux distributions
Systemd
What does the exec() family of system calls do?
Terminates the current running program and replaces it with a new specified program that starts executing in its main function?
The low address is the ___________.
Text
What does the child process inherit after a fork() call?
The child process inherits a copy of the parent's memory space, but they do not share the same memory as both parent and child processes will execute in their own environments
What is the degree of multiprogramming?
The number of programs in memory. Controlled by the long-term scheduler.
The process that initiates fork() becomes __________.
The parent process of the newly created child process.
The CPU executes one instruction of the process after another until _________________
The process completes or another event occurs.
Blocked
Unable to continue without event occurring, e.g. I/O
Where is the process context stored?
User level context in memory
Why would wait() or waitpid() fail?
Usually when no child exists to wait on.
What are the two uses for fork()?
When a process wants to duplicate itself so that the parent and child can each execute different sections of code at the same time or when a process wants to execute a different program.
What is Init?
a continually-running daemon process (i.e., one that runs in the background) responsible for starting up and shutting down the system. It is invoked by the kernel at the end of the bootstrap procedure.
the process ID ______________ across an exec because a _____________________.
does not change, a new process is not created
What do the wait() and waitpid() system calls do?
force the parent process to suspend execution until the child process has completed
How do you create a new process?
fork()
What exec function takes the full path name of the command and variable length of arguments terminated by NULL?
int execl(const char *path, const char *arg, ...);
What exec() function uses an argument list and environment variables?
int execle(const char *path, const char *arg, ..., char *const envp[] );
What exec function will try to find the command from $PATH, so full path to command is not needed
int execlp(const char *file, const char *arg, ... );
What exec() function is the equivalent of execl, except that the arguments are passed in as a NULL terminated array
int execv(const char *path, char *const argv[]);
What exec() function is the equivalent of execle, the arguments are passed in as a NULL terminated array?
int execve(const char *filename, char *const argv [], char *const envp[] );
What exec function is the equivalent of execlp, except that the arguments are passed in as a NULL terminated array?
int execvp(const char *file, char *const argv[]);
The switching between the parent and child depends on many factors, such as
machine load or system process scheduling
Each process is assigned a unique, non-negative integral _____________
process ID or PID
Command line arguments are specified as ________________________________.
separate arguments or we have to build an array of pointers to the arguments and pass the address of the array
What is the ready queue?
set of all processes residing in main memory, ready and waiting to execute
I/O-bound process
spends more time doing I/O than computations, many short CPU bursts
Programs can create ________________.
sub-processes to execute concurrently.
In the case of a fork() being called in a shell...
the child typically does an exec() right after it returns from the fork.
The more precise definition of a process is
the context maintained for an executing program.
Context-switch time is overhead, meaning
the system does no useful work while switching
When the fork request arrives in a network server, the parent __________________
waits for a service request from the client
What does waitpid() do
waits for a specific child process identified by its PID
