09 - Kernel and processes Flashcards
What is the primary role of an Operating System (OS) in the context of process management?
- The OS plays a central role in process management.
- It isolates applications to prevent them from affecting each other negatively.
- This isolation is fundamental to ensuring system reliability, security, privacy, and fairness.
Define a process and a thread in the context of operating systems.
- A process is an instance of a running program with limited rights.
- A thread is a sequence of executed instructions within a process.
- A process can have potentially many threads.
- The address space of a process defines its accessible memory and other permissions.
What hardware mechanisms support process protection in operating systems?
- Privileged instructions, available only to the kernel.
- Memory access limits to prevent user code from overwriting kernel space.
- Timers to regain control from user programs.
- Safe ways to switch between user and kernel modes.
Explain the concept of dual-mode operation in the context of operating systems.
- Dual-mode operation includes Kernel mode (full hardware privileges) and User mode (limited privileges).
- Memory protection is achieved through different base and bound registers for kernel and user-level processes.
- This approach ensures safe control transfer between modes and protects kernel memory from user programs.
What is the role of system calls in operating systems?
- System calls provide an interface for applications to interact with the operating system.
- They are used for various operations like process control, file management, device management, information maintenance, and communication.
- In Linux, the number of system calls has increased from around 60 in the first Unix version to over 300 in current versions.
Explain the differences between system calls and library functions.
- System calls are provided by the system and are executed (mostly) in the system kernel.
- They are entry points into the kernel and are therefore NOT linked into your program.
- The source code is not portable
- The API is portable
- Library calls include the ANSI C standard library and are therefore portable. These functions are linked into your program.
How does the kernel handle system calls?
- The kernel uses a stub to locate arguments either in registers or on the user stack.
- It translates user addresses to kernel addresses and copies arguments from user memory to kernel memory.
- The kernel protects itself from malicious code and validates arguments to prevent errors.
- After executing the handler, it copies results back into user memory.
Slide 24, chapter 9
What is User Level Process Management in UNIX?
- User Level Process Management allows processes to create other processes without the need for kernel recompilation.
- This capability is utilized by shell command line interpreters.
- It includes functionalities for job control, such as creation, killing, suspending, and resuming processes.
- Additionally, it provides a job coordination system for pipe-lining and sequencing of processes
What happens when a program is compiled in UNIX?
- Compiling a program, like cc -c file1.c, creates a new process.
- The cc program reads the file and produces output.
- The shell waits for the completion of this process.
- The compilation process can be defined in a file, becoming a program
Describe the kernel operations involved in process creation.
- The kernel allocates process data-structures.
- It allocates memory for the process.
- The program is copied from disk to the allocated memory.
- Stacks are allocated: user-level for functions and kernel-level for system-calls/interrupts.
What occurs during process startup in UNIX?
- The kernel copies arguments from user memory (argc/argv).
- It copies the environment settings.
- Control is transferred to user mode using POP and IRET instructions.
- This occurs after manipulation of the kernel stack
What steps are involved in process termination?
- The
exit
system call is invoked, typically inserted by the compiler. - The kernel executes this call, leading to:
- Freeing of stacks.
- Freeing of process memory.
- Freeing of kernel data-structures.
- Notification to the “parent” process of the termination.
What are the different policies for process creation in UNIX?
- Execution mode policies include whether the father and son processes execute in parallel or if the father blocks until the son terminates.
- Memory management policies determine if the son process gets new memory (data and code), new data, a shared copy of the father’s memory, or a non-shared copy.
- Resource sharing policies cover whether the father and son share all, some, or no resources (like open files, IPC objects, etc.).
How does process creation work in Windows?
- The
CreateProcess
function is used to create and initialize the Process Control Block and the address space. - It loads the program into the address space and copies arguments into process memory.
- The function initializes the hardware context and informs the scheduler of the new process.
- Further security configuration, like limiting privileges and changing priority, is necessary.
What are the process creation policies in Windows?
- In Windows, the execution mode policy is that the father and son execute in parallel.
- For memory management, the son gets new memory (data and code).
- Regarding resource sharing, the father and son do not share most of the resources.
What are the key steps in UNIX process management?
- UNIX process management involves two steps: copying the current process and executing a different program.
- Key system calls include
fork
for creating a copy of the current process,exec
for changing the program run by the current process,wait
for waiting for a process to finish,signal
for sending notifications to other processes.
What are the key policies in UNIX process creation?
- Execution mode: Parent and child processes can execute in parallel.
- Memory management: The child process can receive a non-shared or shared copy of the parent’s memory.
- Resource sharing: Parent and child processes can share all, some, or no resources (e.g., files, IPC objects).
How does the UNIX fork system call function?
- The fork call creates a new process, duplicating the current process.
- It returns twice: once in the parent process (returns child PID) and once in the child process (returns 0).
- After fork, changes in variables are local to each process.
Describe the execve system call in UNIX.
-
execve()
executes a program specified by a filename. - It replaces the current process image with a new one, loading the program into the current address space.
- Arguments and environment variables are passed to the new program, and previous process state is lost.
What is the purpose of the ‘system’ function in UNIX?
- The system function is used to execute a shell command in a new process.
- It combines fork and execve: the child process executes the command, and the parent waits for its completion.
- The function returns the exit code of the child process.
How does UNIX handle the return codes of processes?
- The parent process can retrieve the child’s return code using wait or waitpid functions.
- A process is considered a zombie until its return code is collected by its parent.
- The operating system maintains information about the terminated process and its return code until the parent processes it.
What is the function of posix_spawn in process creation?
-
posix_spawn()
creates a new child process that executes a specified file. - It is used on systems that lack support for the fork(2) system call, typically on small embedded systems without MMU support.
- This function replicates shell behavior for process creation.
What are zombies in UNIX and how are they handled?
- A zombie is a process that has completed execution but still has an entry in the process table.
- It remains until its parent calls wait to clean up and collect the exit status.
- If a parent process doesn’t call wait, the child remains a zombie, which can lead to resource depletion.
How are processes identified in UNIX?
- Each process in UNIX is identified by a Process ID (PID), which is a unique number.
- Processes can find out their own PID using the getpid system call.
- The maximum value for PID is usually 32768.
What are signals in UNIX and how do they function?
- Signals are a mechanism for handling asynchronous events in UNIX.
- They inform a process that a particular event has occurred.
- Examples include illegal memory access, process abortion (Ctrl-C), or system call-generated events (like a son process termination).
- Processes interact with the kernel using system calls, while the kernel uses signals to interact with processes.
What are the methods for handling signals?
- Polling: Processes check periodically for events, but it’s inefficient and not always correct.
- Upcalls: Kernel notifies processes of events, allowing for efficient and direct handling.
- Signals can be handled by default (kernel action), ignored, or managed with a user-level handler.
How are signals handled in UNIX?
- Default handling: The kernel handles the signal, usually terminating the process.
- Ignoring the signal: The process does not acknowledge the signal.
- Handling with a user-level handler: Custom code in the process executes in response to the signal.
- Some signals like SIGKILL and SIGSTOP cannot be ignored or handled and must be executed by default.
What are some examples of UNIX signals and their default actions?
SIGHUP (1): Terminates the process due to terminal line hangup.
SIGINT (2): Terminates the process due to an interrupt program (Ctrl-C).
SIGQUIT (3): Terminates the process and produces core dumps.
SIGKILL (9): Kills the process.
SIGALRM (14): Indicates a timer has expired.
SIGCHLD (20): Ignored, indicates child status has changed.
SIGSTOP (17): Stops the process.
SIGCONT (19): Continues if stopped.
How do you register a signal handler in UNIX?
- Use the signal() function from <signal.h>.</signal.h>
- The function takes the signal code (SIGXXX) and a pointer to the signal handler function.
- It can also take SIG_IGN for ignoring the signal or SIG_DFL for default handling.
- The function returns the previous signal handler.