Mini test 2 Flashcards
Processes
an instance of a running program
functionality of Processes
provides logical control flow and private address space
management of Processes
OS uses context switching and virtual memory
purpose of fork
creates a new child process
behavior of forking
returns twice: once in the parent (child’s PID) and once in the child (0)
characteristics of forking
child gets a copy of the parent’s address space and file descriptors
exec function
replaces the current process memory with a new program
exec usage
execve is a common variant that loads and runs a program
details of exec
maintains PID but overwrites memory, stack, and code
Process Graphs
visualize the partial ordering of operations in concurrent programs
features of Process Graphs
nodes represent operations; edges indicate execution order
Zombies
processes that have completed execution but still have an entry in the process table
cause of Zombies
occur when a parent process doesn’t immediately perform a wait to collect the child’s termination status
resolution of Zombies
parent performs reaping using wait or waitpid
functionality of wait
pauses the parent until any child terminates; reaps zombie processes
functionality of waitpid
more specific that wait, can wait for a specific process
wait/waitpid options
can use various flags to modify behavior, such as non-blocking waits
Signals
notifications sent to a process by the OS indication that an event has occurred
types of Signals
identified by integer IDs, like SIGINT for interrupt and SIGKILL for termination
behavior of Signals
can be ignore, terminate the process, or be caught by a custom handler
Traps
intentional, such as system calls of breakpoints; control returns to next instruction
Faults
unintentional but can be recoverable; may re-execute the faulting instruction
Aborts
unintentional and unrecoverable; leads to program termination
Signal Handlers
custom functions defined by a program to respond to specific signals
installation of Signal Handlers
use signal() or sigaction() to set a handler
safety of Signal Handlers
handlers should be simple and only use async-signal-safe functions
Blocking Signals mechanism
prevents the process from receiving certain signals temporally
Blocking Signals usage
useful during critical sections of code to avoid interruptions
Blocking Signals methods
sigprocmask() to block/unblock signals and sigsuspend() to wait for a set of blocked signals to occur
I/O Basics
Involves copying data between main memory and external sources like disk drives and terminals
I/O Unix Model
Treats all I/O devices as files, allowing for uniform file operations across devices
Open files
open() system call is used to access a file; returns a file descriptor if successful
Close file
close() system call releases resources associated with a file; important to check return status for errors
File Descriptor
Small, non-negative integer that identifies an open file for the process
Open File
Represents an actual instance of an open file, including its current position, access modes, and links to file data
V-node Tables
Low-level structures that store metadata about a file, such as permissions, owner, size, and pointers to data blocks
Shared/Unshared I/O Between Parent and Child Processes Inheritance
Child process inherits open file descriptors from its parent upon fork()
Shared/Unshared I/O Between Parent and Child Processes Independence
Despite sharing file descriptors, file offset and file status flags are copied, allowing independent file operations
Redirection (dup2) Purpose
dup2() system call is used to copy a file descriptor to another, replacing the latter, useful for I/O redirection
Redirection (dup2) Common Use
Redirect output or input of a process to/from a file or another process
Pipes Functionality
Allows for one-way communication between two processes; typically used to connect the output of one process to the input of another
Pipes Implementation
Created using the pipe() system call which returns two file descriptors; one for reading and the other for writing