Exceptions, Interrupts, and Signals Flashcards
Process
Executing instance of a program. Separate mem address spaces. Resource heavy-weight
Thread
Entity within a process that can be schedules for code execution. Each process has at least one thread. Share mem address space, opened files, and more. Resource light-weight
Thread Pros and Cons
PROS: Cheaper to create thread. Cheaper task switch. cheaper data sharing
CONS: One bug or attack in thread makes whole process unstable (bc of data sharing).
Exceptions
Event that interrupt the normal execution of a program or a system, causes mode switch
Types of Exceptions
- Programmed exception (traps)
- Anomalous executions (faults)
Programmed Exceptions (traps)
‘int 0x80’ (system call), ‘int 3’ (single-step debugging)
Anomalous Executions (faults)
Divide by zero, dereference null pointer.
How is ‘divide by zero’ handled?
- CPU executing division triggers exception
- Mode switch to kernel, divide by zero handler invoked automatically
- Handler sends SIGFPE to faulty process, mode switch back to user space
- If process has SIGFPE handler then executes it. Otherwise default handler in libc kills the process
Signal Causes
- “kill -signame pid”
- “pthread_kill()”, sends signals to specific thread within sender’s process
- “tgkill(pid, tid, sig)”, send signal to thread ‘tid’ in process ‘pid’
- “sigqueue(pid, sig, value)”, sends signal and associated value to process ‘pid’
When does SIGCHLD happen?
What a process exits, the parent process receives a SIGSHLD.
Thread Signal Handler
Handlers are shared among threads of a process, while signal mask is per thread.
sigaction()
Used to change default signal handler to be customized.
signal()
Like sigaction(). After invocation of your handler, default is restored, so not reliable.
Vector
Number in [0,255] used to identify an interrupt or exception. Can be specified by programmer
IDT
Interrupt Descriptor Table. Each entry is a descriptor that refers to an interrupt or exception handler.
Interrupt/Exception Hander
- Mode switch to kernel mode in is currently in user mode
- Save current context
- Invoke corresponding handler function using IDT and interrupt/exception vector
- Restore context
- Mode switch back to user mode in needed
fork()
Parent process receives child process id and child receives 0 (but child id isn’t actually 0)
exec()
Changes the program that is being executed. All code is overwritten with new program.
wait()
Suspends execution of the calling process until one of its children terminate.
How does computer HARDWARE respond to a keystroke?
- Interrupt generated by keyboard
- CPU notices interrupt and sets program counter to corresponding interrupt handler
Zombie
Occurs once a child process exits. Occupies important resources. Cleaned up by:
- parent waiting w wait()
- parent explicitly ignores SIGCHLD by setting handler to SIG_IGN
- if parent exits, zombie gets reaped by init()
How does computer SOFTWARE-KERNEL respond to a keystroke?
- interrupt handler executes the device driver for the keyboard
- handler then reads character from keyboard buffer to kernel-space buffer
How does computer SOFTWARE-USER/KERNEL respond to a keystroke?
- process that waits for input is waken up
- kernel copies character from the kernel space to the user-space buffer