0% found this document useful (0 votes)
4 views12 pages

Unit 2 Lecture 37 - Signals

The document discusses signals in operating systems, particularly in UNIX and Linux environments, explaining their purpose as notifications for processes regarding specific events. It outlines the difference between synchronous and asynchronous signals, their handling methods, and the role of signal handlers. Additionally, it touches upon signal handling in multithreaded programs and compares UNIX signal handling with Windows' asynchronous procedure calls (APCs).

Uploaded by

ayesha45583
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Unit 2 Lecture 37 - Signals

The document discusses signals in operating systems, particularly in UNIX and Linux environments, explaining their purpose as notifications for processes regarding specific events. It outlines the difference between synchronous and asynchronous signals, their handling methods, and the role of signal handlers. Additionally, it touches upon signal handling in multithreaded programs and compares UNIX signal handling with Windows' asynchronous procedure calls (APCs).

Uploaded by

ayesha45583
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

OPERATING SYSTEMS

Signals

Suresh Jamadagni
Department of Computer Science
OPERATING SYSTEMS
Slides Credits for all the PPTs of this course

• The slides/diagrams in this course are an adaptation,


combination, and enhancement of material from the following
resources and persons:

1. Slides of Operating System Concepts, Abraham Silberschatz,


Peter Baer Galvin, Greg Gagne - 9th edition 2013 and some
slides from 10th edition 2018
2. Some conceptual text and diagram from Operating Systems -
Internals and Design Principles, William Stallings, 9th edition
2018
3. Some presentation transcripts from A. Frank – P. Weisberg
4. Some conceptual text from Operating Systems: Three Easy
Pieces, Remzi Arpaci-Dusseau, Andrea Arpaci Dusseau
OPERATING SYSTEMS

Signals

Suresh Jamadagni
Department of Computer Science
OPERATING SYSTEMS
Signals

• A signal is used in UNIX systems to notify a process that a particular event has occurred.
• A signal may be received either synchronously or asynchronously depending on the source of
and the reason for the event being signaled
• All signals, whether synchronous or asynchronous, follow the same pattern:
1. A signal is generated by the occurrence of a particular event.
2. The signal is delivered to a process.
3. Once delivered, the signal must be handled.
OPERATING SYSTEMS
Signals – synchronous and asynchronous

• Examples of synchronous signal include illegal memory access and division by 0.


• If a running program performs either of these actions, a signal is generated.
• Synchronous signals are delivered to the same process that performed the operation that caused
the signal (that is the reason they are considered synchronous).
• When a signal is generated by an event external to a running process, that process receives the
signal asynchronously.
• Examples of such signals include terminating a process with specific keystrokes (such as
<control><C>) and having a timer expire.
• Typically, an asynchronous signal is sent to another process.
OPERATING SYSTEMS
Signal handlers

• A signal may be handled by one of two possible handlers:


1. A default signal handler
2. A user-defined signal handler
• Every signal has a default signal handler that the kernel runs when handling that signal.
• This default action can be overridden by a user-defined signal handler that is called to handle
the signal.
• Signals are handled in different ways. Some signals (such as changing the size of a window) are
simply ignored; others (such as an illegal memory access) are handled by terminating the
program.
OPERATING SYSTEMS
Signal handling

• Handling signals in single-threaded programs is straightforward: signals are always delivered to a


process.
• Delivering signals is more complicated in multithreaded programs, where a process may have
several threads.
• In general, the following options exist:
1. Deliver the signal to the thread to which the signal applies.
2. Deliver the signal to every thread in the process.
3. Deliver the signal to certain threads in the process.
4. Assign a specific thread to receive all signals for the process.
OPERATING SYSTEMS
Signal handling

• The method for delivering a signal depends on the type of signal generated.
• For example, synchronous signals need to be delivered to the thread causing the signal and not
to other threads in the process.
• However, the situation with asynchronous signals is not as clear. Some asynchronous signals—
such as a signal that terminates a process (<control><C>) should be sent to all threads.
• The standard UNIX function for delivering a signal is
kill(pid t pid, int signal)
• This function specifies the process (pid) to which a particular signal (signal) is to be delivered
OPERATING SYSTEMS
Signal handling

• Most multithreaded versions of UNIX allow a thread to specify which signals it will accept and
which it will block.
• An asynchronous signal may be delivered only to those threads that are not blocking it.
• Because signals need to be handled only once, a signal is typically delivered only to the first
thread found that is not blocking it.
• POSIX Pthreads provides the following function, which allows a signal to be delivered to a
specified thread (tid):
pthread kill(pthread t tid, int signal)
OPERATING SYSTEMS
Signals in windows

• Windows does not explicitly provide support for signals, it allows to emulate them using
asynchronous procedure calls (APCs).
• The APC facility enables a user thread to specify a function that is to be called when the user
thread receives notification of a particular event.
• An APC is roughly equivalent to an asynchronous signal in UNIX
• The APC facility is more straightforward, since an APC is delivered to a particular thread rather
than a process
OPERATING SYSTEMS
Signals in Linux

• A signal is a kind of software interrupt, used to announce asynchronous events to a process


• SIGINT is a signal generated when a user presses Control-C. This will terminate the program from
the terminal.
• SIGALRM is generated when the timer set by the alarm function goes off.
• SIGABRT is generated when a process executes the abort function.
• SIGSTOP tells LINUX to pause a process to be resumed later.
• SIGCONT tells LINUX to resume the processed paused earlier.
• SIGSEGV is sent to a process when it has a segmentation fault.
• SIGKILL is sent to a process to cause it to terminate at once.
THANK YOU

Suresh Jamadagni
Department of Computer Science and Engineering
[email protected]

You might also like