09 - Kernel and processes Flashcards

1
Q

What is the primary role of an Operating System (OS) in the context of process management?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define a process and a thread in the context of operating systems.

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What hardware mechanisms support process protection in operating systems?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the concept of dual-mode operation in the context of operating systems.

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of system calls in operating systems?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the differences between system calls and library functions.

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the kernel handle system calls?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is User Level Process Management in UNIX?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when a program is compiled in UNIX?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the kernel operations involved in process creation.

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What occurs during process startup in UNIX?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What steps are involved in process termination?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the different policies for process creation in UNIX?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does process creation work in Windows?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the process creation policies in Windows?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the key steps in UNIX process management?

A
  • 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.
17
Q

What are the key policies in UNIX process creation?

A
  • 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).
18
Q

How does the UNIX fork system call function?

A
  • 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.
19
Q

Describe the execve system call in UNIX.

A
  • 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.
20
Q

What is the purpose of the ‘system’ function in UNIX?

A
  • 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.
21
Q

How does UNIX handle the return codes of processes?

A
  • 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.
22
Q

What is the function of posix_spawn in process creation?

A
  • 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.
23
Q

What are zombies in UNIX and how are they handled?

A
  • 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.
24
Q

How are processes identified in UNIX?

A
  • 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.
25
Q

What are signals in UNIX and how do they function?

A
  • 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.
26
Q

What are the methods for handling signals?

A
  • 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.
27
Q

How are signals handled in UNIX?

A
  • 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.
28
Q

What are some examples of UNIX signals and their default actions?

A

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.

29
Q

How do you register a signal handler in UNIX?

A
  • 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.