LU4 Signal Flashcards
What is a signal in UNIX/Linux systems?
a software interrupt.
What are signals also referred to as?
Software interrupts.
Name three examples of events that can trigger signals.
- Floating point error (SIGFTE)
- power failure (hardware)
- alarm clock ‘ring’ (software)
- User action (SIGINT/SIGTSTP)
What is the purpose of signals in UNIX/Linux?
To handle asynchronous events.
What does asynchronous mean in the context of signals?
The event can occur at any time and may be unrelated to the execution of the process.
What happens when UNIX/Linux recognizes an event?
It sends the corresponding process a signal.
What are the three actions a process can take when a signal occurs?
[ CID ]
- CATCH the signal
- IGNORE the signal,
- let DEFAULT action apply.
Which signals cannot be ignored?
SIGKILL and SIGSTOP.
What does catching a signal mean?
Telling the kernel to call a user-defined function.
What is the default action of a signal?
Every signal has a default action which could be:
[TIS]
- terminating the process
- ignoring the signal
- suspending the process.
What does SIGFPE
represent?
Floating point error.
Signal Floating-Point Exception
What does SIGSEGV represent?
Segment violation.
a signal sent to a process by the OS when it attempts to access a memory location that it is not allowed to access. This typically occurs due to programming errors.
What signal is sent when Control-C is pressed?
SIGINT
(Signal Interrupt)
What signal is sent when Control-Z is pressed?
SIGTSTP
(Signal Terminal Stop)
What signal is generated when a child process dies?
SIGCHLD
(Signal Child)
What header file must be included to use signals in C?
signal.h
What is the signal number for a floating point error?
8.
What is the lifetime of a signal?
The interval of generation (creation) to delivery (handling or ignoring). Once delivered, it no longer exists.
Create —> Delivered
What does it mean if a signal is pending?
It has been generated but not yet delivered.
How can you send a signal from the command line?
Using the kill command, e.g., kill -9 3423.
What does the signal() system call do?
It allows a process to specify the action to take when a particular signal is received.
#include <stdio.h> #include <signal.h> #include <unistd.h> int alarmFlag = 0; void alarmHandler(int signum) { alarmFlag = 1; } int main() { signal( SIGINT, alarmHandler ); printf("Looping…\n"); while( !alarmFlag ) { pause(); } printf("Loop ends due to alarm signal \n"); return 0; }
What is the syntax of the signal() function?
void ( *signal(int signo, void (*func)(int)) ) (int);
- Takes a signal number (signo) and a signal handler function (func).
- Returns the previous signal handler (which is also a function pointer).
What does SIG_IGN
indicate in the signal() function?
The specified signal should be ignored and discarded.
meaning the program will not take any action when that signal is received
oldHandler = signal(SIGINT, SIG_IGN);
to ignore the CTRL-C/SIGINT signal
What does SIG_DFL
indicate in the signal()
function?
The kernel should use the default handler.