Lecture 05 Flashcards

1
Q

What is a ‘signal’?

A

A mechanism to notify a process that a particular event has occurred.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A signal is:
A - Synchronous
B - Asynchronous

A

B - Asynchronous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a software interrupt cause?

A

An immediate jump to handler code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens after an interrupt handler finishes?

A

Execution resumes at the original point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are functions async-signal-safe?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A signal is identified using what?

A

A unique integer value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are four default actions that a program may take when it encounters a signal?

A
  • Terminate
  • Terminate and dump memory contents into a ‘core’ file
  • Stop
  • Ignore
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What function is used to send a signal to the current process?

A

raise

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the function prototype for the ‘raise’ function?

A

int raise(int sig);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What function is used to send a signal to another process?

A

kill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the function prototype for the ‘kill’ function?

A

int kill(pid_t pid, int sig);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What signal is sent when you press Ctrl-C on a process?

A

SIGINT (interrupt)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What signal is sent when you press Ctrl-Z on a process?

A

SIGTSTP (Stop that can be handled)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What signal stops a process without giving it a chance to handle it?

A

SIGSTOP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What function is used to register a signal handler?

A

signal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the function prototype for ‘signal’?

A

sighandler_t signal(int signum, sighandlet_t handler);

17
Q

How many handlers can exist per signal?

A

One

18
Q

What happens when a new handler is added for a signal which already has one?

A

The old handler is overwritten with the new one.

19
Q

Is it possible to add a handler for SIGSTOP and SIGKILL?

A

No

20
Q

What is the argument given to a signal handler function?

A

The signal that was raised.

21
Q

What single line of code will make a program ignore a Ctrl-C interrupt?

A

signal(SIGINT,SIG_IGN)

22
Q

What key presses send a SIGINT signal to a process?

A

Ctrl-C

23
Q

What key presses send a SIGQUIT signal to a process?

A

Ctrl-/

24
Q

What key presses send a SIGTSTP signal to a process?

A

Ctrl-Z

25
Q

What does the alarm function do?

A

Sets a timer for a specified number of seconds. When the timer expires, SIGALRM is raised.

26
Q

What is the default action of ‘SIGALRM’?

A

Terminate the process

27
Q

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);
}
A

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.