Lecture 05 Flashcards
What is a ‘signal’?
A mechanism to notify a process that a particular event has occurred.
A signal is:
A - Synchronous
B - Asynchronous
B - Asynchronous
What does a software interrupt cause?
An immediate jump to handler code.
What happens after an interrupt handler finishes?
Execution resumes at the original point.
Are functions async-signal-safe?
No
A signal is identified using what?
A unique integer value.
What are four default actions that a program may take when it encounters a signal?
- Terminate
- Terminate and dump memory contents into a ‘core’ file
- Stop
- Ignore
What function is used to send a signal to the current process?
raise
What is the function prototype for the ‘raise’ function?
int raise(int sig);
What function is used to send a signal to another process?
kill
What is the function prototype for the ‘kill’ function?
int kill(pid_t pid, int sig);
What signal is sent when you press Ctrl-C on a process?
SIGINT (interrupt)
What signal is sent when you press Ctrl-Z on a process?
SIGTSTP (Stop that can be handled)
What signal stops a process without giving it a chance to handle it?
SIGSTOP
What function is used to register a signal handler?
signal
What is the function prototype for ‘signal’?
sighandler_t signal(int signum, sighandlet_t handler);
How many handlers can exist per signal?
One
What happens when a new handler is added for a signal which already has one?
The old handler is overwritten with the new one.
Is it possible to add a handler for SIGSTOP and SIGKILL?
No
What is the argument given to a signal handler function?
The signal that was raised.
What single line of code will make a program ignore a Ctrl-C interrupt?
signal(SIGINT,SIG_IGN)
What key presses send a SIGINT signal to a process?
Ctrl-C
What key presses send a SIGQUIT signal to a process?
Ctrl-/
What key presses send a SIGTSTP signal to a process?
Ctrl-Z
What does the alarm function do?
Sets a timer for a specified number of seconds. When the timer expires, SIGALRM is raised.
What is the default action of ‘SIGALRM’?
Terminate the process
What will this C code do?
void sigint_h(int signum){ printf("Caught SIGINT\n"); signal(SIGINT,SIG_DFL); }
int main(void){ signal(SIGINT, sigint_h); while(1); }
The process will do nothing in an endless loop.
The first time the user hits Ctrl-C, it will print ‘Caught SIGINT’ and continue.
The second time, it will use the default handler and exit.