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.