SlideShare a Scribd company logo
1 of 39
Download to read offline
Linux For Embedded Systems
ForArabs
Ahmed ElArabawy
Course 102:
UnderstandingLinux
Lecture 19:
Using Signals
HW Platform
UserSpaceKernelSpace
Device Drivers
Linux Kernel
Process 2Process 1
SystemCall
Signal
Signal
User Applications
What is a Signal ??
• Linux has two planes:
• Kernel Plane: Has access to system and hardware resources
• User Plane: For applications to run on
• User applications don’t have direct access to the kernel
• For a user application to communicate with the kernel, it
needs to use a System Call
• What about if the kernel needs to send a
request/command/notification/… to the user application ??
• The used mechanism is Signals
• So, Signals are the mechanism that the kernel uses to
communicate with the user applications
• Signals are also used between user applications (when one
application needs to send a request/command to the other
application)
What is a Signal ??
• Signal is the communication channel used by the Linux Kernel to
communicate with a process running in the user plane
• This can be used by the kernel to kill a process, stop it, resume it,
notify it of a timer expiry, etc…
• Signals can also be sent by another process running in the user
plane. Examples,
• When the user presses Ctrl-c to terminate the running application, or
Ctrl-z to stop it
• When the user uses the command “bg” to resume a stopped
application in the background, or “fg” to resume it in the foreground
• When the user uses the “kill” command to terminate a running
application
• In all of these cases, a signal is sent to the destination application to
achieve the required task
• When sent by another user application, it is first passed to the
kernel in a system call, which in turn passes it back to the desired
process
Signals
• Signals are described in both Unix Systems and POSIX
Standard
• There are a table of signals. Each signal has,
• Signal number
• Signal name (starting with ‘SIG’)
• Signals with numbers (1-31) are normal signals
• Signals with numbers > 31 are called “Real Time Signals”
Passing a Signal to a Process
(kill Command)
$ kill <pid>
$ kill -<Signal number> <pid>
$ kill <Signal name> <pid>
• The kill command passes a signal to the desired process
• Note that, despite that the command name is ‘kill’, it is used for all
types of signals even those that have different purposes and not just
used to kill processes
• If no signal is specified, then the signal SIGTERM is assumed by
default
• Examples:
$ kill -9 1185
$ kill SIGKILL 1185
Identical commands
Other ways to “kill”
Selecting Processes by name
(killall Command)
$ killall <Signal> <command name>
• The command killall sends the desired signal to all processes
running the specified command
$ killall chrome
• This is useful when you need to pick a process without
searching for its pid
• Also useful when you need to send the signal to all instances
of the running program
• If no signal is specified, SIGTERM is assumed
• Example:
$ killall -9 gedit (this sends a SIGKILL signal to all “gedit” instances)
Selecting Processes by Other Criteria
(pkill Command)
$ pkill <signal> -u <username>
$ pkill <siganal> -P <Parent process>
$ pkill <signal> <pattern for command>
$ pkill <signal> -t <Terminal name>
• The pkill command sends the desired signal to processes that match
different criteria
• Examples:
• Send a SIGTERM to all processes owned by user tom
$ pkill -u tom
• Send a SIGSTOP to all processes running under tty1 terminal
$ pkill SIGSTOP -t tty1
• Send SIGTERM to all children of process with pid 1107
$ pkill –P 1107
Killing GUI Processes with the Mouse
(the xkill Command)
$ xkill
• The xkill command allows the user to select the process to kill
with the mouse
• Type the command, then click with the mouse on the UI of the
process you want to kill
Dealing with Hanging GUI Apps
• If a GUI app is hanging, and you need to kill it but unable due
to the hanging screen
• get into a Linux virtual terminal via,
[Ctrl] [Alt] [F1]
• From the virtual terminal, issue the proper “kill” command
$ killall -9 chrome
• After you are done, get back to the tty-7 (for the X window)
[Alt] [F7]
Listing Signal Names
Real time Signals
• Those are the signals with numbers > 31
• They don’t have a pre-defined function, and it is left to the
user/developer to use
• Defined by the programmer
• Guaranteed order of delivery
Triggers for Sending Signals
Keyboard Hot keys
• Some signals are triggered by the user by typing special hot-
keys
• When the kernel detects these hot-keys, it sends the proper
signal to the running process (or process group)
• Examples:
• Ctrl-c triggers SIGINT
• Ctrl-z triggers SIGTSTP
• Ctrl- triggers SIGQUIT
Request from another process
• A process can trigger the kernel to send a signal to another
process by issuing a system call
• Examples for this is when the user issue the commands from
the terminal
$ kill (triggers sending the desired signal, SIGTERM by default)
$ fg (triggers sending the signal SIGCONT)
$ bg (triggers sending the signal SIGCONT)
• A process can also trigger sending a signal to another process
programmatically via some special function API
A Hardware Event
• Hardware events can trigger the kernel to send a signal to the
proper process
• An example of that, when the kernel detects a modem
disconnection, it sends the signal SIGHUP to all processes
using this session
Death of a Related Process
• When a process terminates, the kernel sends the following signals,
• A SIGHUP is sent to all children processes to inform them about the
death of their parent process
• A SIGCHLD is sent to the parent of the terminated process to inform it
about the death of a child process
Errors and Exceptions
• Some exceptions within the process triggers the kernel to
send signals to the process,
• Examples:
• If the process tries to execute an illegal instruction, the kernel is
triggered to send SIGILL signal to it
• If the process suffers from a Floating Point Exception, the kernel
sends it a SIGFPE
• If the process tries to write to a pipe while the other end is not
listening, the kernel sends it a SIGPIPE
• If the process accesses a Null Pointer (or other memory
exceptions), the kernel sends it SIGSEGV
• If a process running in the background tries to read/write to the
standard input/output, the kernel will send it a SIGTTIN/SIGTTOU
• If the process exits on error using the abort(), the kernel will send
it SIGABRT
Notification By the Kernel
• Sometimes, a process would ask the kernel for some
notification when some event happens
• Normally, the process will be waiting for this notification
• The kernel delivers this notification via a signal
• Examples:
• The kernel will use the signal SIGALRM and SIGVTALRM to notify
the process of a timer expiry
• A process can ask the kernel for a notification whenever a file
handler has been accessed
Process Response to Signals
Default Action
• When a process receives a signal, the normal behavior is to execute
the default action
• Each signal has its own default action that is part of its description
• Examples:
• Some signals have the default action of termination (graceful
termination). This is applicable for several signals such as SIGTERM,
SIGPIPE, SIGUSR1, SIGUSR2, …
• Some signals have the default action of termination with generation
of a core dump (stack trace for further debugging). This action is
useful for signals that indicate some error in the process operation
such as SIGSEGV, SIGILL, SIGABRT, SIGQUIT …
• Some signals have the default action of being ignored by the process
such as SIGCHLD
• Some signals does not allow the process to change its default action.
This means that the default action is the only allowed action. This
includes the SIGSTOP which force the process to stop (suspend) and
SIGKILL which force the process to terminate immediately
Ignoring a Signal
• A process can set itself to ignore certain incoming signals,
accordingly no action is performed when these signals are
received
• Some signals can not be ignored such as SIGSTOP, and SIGKILL
Blocking a Signal
• A process can set itself to block a certain set of signals
• Blocking a signal means, keeping it in a queue for later
handling (when the blocking is taken away)
• This is used when the process is executing some code that
should not be interrupted by the incoming signals
• Every process has a mask of which signals to block
• Only one signal of a certain type will be blocked (other
instances will be dropped).
• This last rule does not apply to real time signals (signals with
numbers > 31)
• Some signals can not be blocked (SIGSTOP and SIGKILL)
Catching the Signal
• A process can “catch the signal” before its default handler
executes, and pass it to a special handler
• This is specially useful for some of the signals that have their
default action of being ignored (such as SIGCHLD)
• Some signals can not be caught (SIGSTOP and SIGKILL)
Popular Signals
Hang-Up Signal (1)
SIGHUP
• The hang-up signal is used by the kernel to inform the processes
running in a tty session when the session closes. This can be due to,
• The modem for the session disconnects
• The network connection used to connect to the machine breaks
• It is commonly used to request daemon processes to re-read their
configuration file
• Default action for this signal for the process to terminate
Interrupt Signal (2)
SIGINT
• Interrupt signal is triggered when the user uses the hot-key Ctrl-c
• This causes the kernel to send SIGINT to the currently running
process group
• The default action for this signal is for the process to terminate
Quit Signal (3)
SIGQUIT
• The quit signal is triggered by the user when he uses the hot-
keys Ctrl-
• This triggers the kernel to send SIGQUIT to all processes in the
currently running process group
• Default action is for the process to quit and generate a core
dump file (to be used for debugging)
Illegal Command Signal (4)
SIGILL
• The illegal command signal is triggered when the process
program tries to execute an invalid instruction
• This may occur in the case of memory corruption of the code
area or in stack memory
• Default action is to terminate and generate a core dump file
Abort Signal (6)
SIGABRT
• The abort signal is sent by the kernel to the process when it
calls the abort() function to indicate an erroneous exit of the
program
• The default action is to terminate and generate a core dump
file
Trap Signal (5)
SIGTRAP
• The trap signal is normally used with debuggers and program
tracers
Bus Error Signal (7)
SIGBUS
• The bus error signal is triggered by an error in the program in
which an attempt was made to access memory incorrectly
• This can be caused by alignment errors in memory access
• The default action is to terminate and generate a core dump
file
Floating Point Exception (8)
SIGFPE
• The floating point exception signal is sent by the kernel to the
process when it falls into an exception while running a floating
point instruction
• The default action is to terminate and generate a core dump
file
Kill Signal (9)
SIGKILL
• The process was explicitly killed by a request from a different
process
• The request is to kill the process immediately and forcibly
without giving it a chance to clean-up
• A process can not ignore, block, or catch this signal
Stop Signals (17 &18)
SIGSTOP & SIGTSTP
• SIGTSTP (terminal Stop) is triggered by pressing Ctrl-z
• This signal causes the process (or process group) to suspend
operation
• SIGSTOP has the same effect with the only difference that it can not
be ignored/blocked/caught by the process while this is possible with
SIGTSTP
• Upon stopping due to either SIGSTOP & SIGTSTP, the process awaits
SIGCONT to resume operation
Terminate Signal (15)
SIGTERM
• The terminate signal is the default signal for the kill command when
no signal is specified
• The default action for SIGTERM is to gracefully terminate the
process (process group) after clean up
http://Linux4EmbeddedSystems.com

More Related Content

What's hot

Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts) Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts) Ahmed El-Arabawy
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Ahmed El-Arabawy
 
Course 101: Lecture 5: Linux & GNU
Course 101: Lecture 5: Linux & GNU Course 101: Lecture 5: Linux & GNU
Course 101: Lecture 5: Linux & GNU Ahmed El-Arabawy
 
Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Ahmed El-Arabawy
 
Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Ahmed El-Arabawy
 
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Ahmed El-Arabawy
 
Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals Ahmed El-Arabawy
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Ahmed El-Arabawy
 
Linux standard file system
Linux standard file systemLinux standard file system
Linux standard file systemTaaanu01
 
Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Ahmed El-Arabawy
 
Embedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewEmbedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewAhmed El-Arabawy
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Ahmed El-Arabawy
 
Course 102: Lecture 9: Input Output Internals
Course 102: Lecture 9: Input Output Internals Course 102: Lecture 9: Input Output Internals
Course 102: Lecture 9: Input Output Internals Ahmed El-Arabawy
 
Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux Ahmed El-Arabawy
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemSadia Bashir
 

What's hot (20)

Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts) Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts)
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
 
Course 101: Lecture 5: Linux & GNU
Course 101: Lecture 5: Linux & GNU Course 101: Lecture 5: Linux & GNU
Course 101: Lecture 5: Linux & GNU
 
Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview
 
Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)
 
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers
 
Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 
Linux standard file system
Linux standard file systemLinux standard file system
Linux standard file system
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1) Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 26: FileSystems in Linux (Part 1)
 
Embedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewEmbedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course Overview
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands
 
Course 102: Lecture 9: Input Output Internals
Course 102: Lecture 9: Input Output Internals Course 102: Lecture 9: Input Output Internals
Course 102: Lecture 9: Input Output Internals
 
Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Linux file system
Linux file systemLinux file system
Linux file system
 

Similar to Course 102: Lecture 19: Using Signals

07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptxKushalSrivastava23
 
Signal Handling in Linux
Signal Handling in LinuxSignal Handling in Linux
Signal Handling in LinuxTushar B Kute
 
13 process management
13 process management13 process management
13 process managementShay Cohen
 
signals & message queues overview
signals & message queues overviewsignals & message queues overview
signals & message queues overviewVaishali Dayal
 
AOS Chapter 6 for internal.docx
AOS Chapter 6 for internal.docxAOS Chapter 6 for internal.docx
AOS Chapter 6 for internal.docxKomlikaTaru
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptxvnwzympx
 
System Programming Assignment Help- Signals
System Programming Assignment Help- SignalsSystem Programming Assignment Help- Signals
System Programming Assignment Help- SignalsHelpWithAssignment.com
 
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTESSOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES4SF20CS057LESTONREGO
 
Describe how to use sanction such that a process can send a payload w.pdf
Describe how to use sanction such that a process can send a payload w.pdfDescribe how to use sanction such that a process can send a payload w.pdf
Describe how to use sanction such that a process can send a payload w.pdfarenamobiles123
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010敬倫 林
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesHelpWithAssignment.com
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfHarika Pudugosula
 
Interrupt in real time system
Interrupt in real time system Interrupt in real time system
Interrupt in real time system ali jawad
 

Similar to Course 102: Lecture 19: Using Signals (20)

07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx
 
Signal Handling in Linux
Signal Handling in LinuxSignal Handling in Linux
Signal Handling in Linux
 
13 process management
13 process management13 process management
13 process management
 
signals & message queues overview
signals & message queues overviewsignals & message queues overview
signals & message queues overview
 
AOS Chapter 6 for internal.docx
AOS Chapter 6 for internal.docxAOS Chapter 6 for internal.docx
AOS Chapter 6 for internal.docx
 
04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
 
System Programming Assignment Help- Signals
System Programming Assignment Help- SignalsSystem Programming Assignment Help- Signals
System Programming Assignment Help- Signals
 
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTESSOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
SOGNAL DAEMON AND PROCESSING CRYPTOGRAPHY NOTES
 
Signals
SignalsSignals
Signals
 
UNIX Notes
UNIX NotesUNIX Notes
UNIX Notes
 
Syslog.ppt
Syslog.pptSyslog.ppt
Syslog.ppt
 
Describe how to use sanction such that a process can send a payload w.pdf
Describe how to use sanction such that a process can send a payload w.pdfDescribe how to use sanction such that a process can send a payload w.pdf
Describe how to use sanction such that a process can send a payload w.pdf
 
Interrupts.ppt
Interrupts.pptInterrupts.ppt
Interrupts.ppt
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010
 
Systems Programming Assignment Help - Processes
Systems Programming Assignment Help - ProcessesSystems Programming Assignment Help - Processes
Systems Programming Assignment Help - Processes
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdf
 
Interrupt in real time system
Interrupt in real time system Interrupt in real time system
Interrupt in real time system
 
운영체제론 Ch20
운영체제론 Ch20운영체제론 Ch20
운영체제론 Ch20
 
Unix signals
Unix signalsUnix signals
Unix signals
 

More from Ahmed El-Arabawy

Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files Ahmed El-Arabawy
 
Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management Ahmed El-Arabawy
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsAhmed El-Arabawy
 
Course 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesCourse 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesAhmed El-Arabawy
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsAhmed El-Arabawy
 
Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Ahmed El-Arabawy
 
Course 101: Lecture 4: A Tour in RTOS Land
Course 101: Lecture 4: A Tour in RTOS Land Course 101: Lecture 4: A Tour in RTOS Land
Course 101: Lecture 4: A Tour in RTOS Land Ahmed El-Arabawy
 
Course 101: Lecture 2: Introduction to Operating Systems
Course 101: Lecture 2: Introduction to Operating Systems Course 101: Lecture 2: Introduction to Operating Systems
Course 101: Lecture 2: Introduction to Operating Systems Ahmed El-Arabawy
 
Course 101: Lecture 1: Introduction to Embedded Systems
Course 101: Lecture 1: Introduction to Embedded SystemsCourse 101: Lecture 1: Introduction to Embedded Systems
Course 101: Lecture 1: Introduction to Embedded SystemsAhmed El-Arabawy
 

More from Ahmed El-Arabawy (10)

C 102 lec_29_what_s_next
C 102 lec_29_what_s_nextC 102 lec_29_what_s_next
C 102 lec_29_what_s_next
 
Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 24: Archiving and Compression of Files
 
Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management Course 102: Lecture 22: Package Management
Course 102: Lecture 22: Package Management
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
 
Course 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesCourse 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment Variables
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild Cards
 
Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu
 
Course 101: Lecture 4: A Tour in RTOS Land
Course 101: Lecture 4: A Tour in RTOS Land Course 101: Lecture 4: A Tour in RTOS Land
Course 101: Lecture 4: A Tour in RTOS Land
 
Course 101: Lecture 2: Introduction to Operating Systems
Course 101: Lecture 2: Introduction to Operating Systems Course 101: Lecture 2: Introduction to Operating Systems
Course 101: Lecture 2: Introduction to Operating Systems
 
Course 101: Lecture 1: Introduction to Embedded Systems
Course 101: Lecture 1: Introduction to Embedded SystemsCourse 101: Lecture 1: Introduction to Embedded Systems
Course 101: Lecture 1: Introduction to Embedded Systems
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Course 102: Lecture 19: Using Signals

  • 1. Linux For Embedded Systems ForArabs Ahmed ElArabawy Course 102: UnderstandingLinux
  • 3. HW Platform UserSpaceKernelSpace Device Drivers Linux Kernel Process 2Process 1 SystemCall Signal Signal User Applications
  • 4. What is a Signal ?? • Linux has two planes: • Kernel Plane: Has access to system and hardware resources • User Plane: For applications to run on • User applications don’t have direct access to the kernel • For a user application to communicate with the kernel, it needs to use a System Call • What about if the kernel needs to send a request/command/notification/… to the user application ?? • The used mechanism is Signals • So, Signals are the mechanism that the kernel uses to communicate with the user applications • Signals are also used between user applications (when one application needs to send a request/command to the other application)
  • 5. What is a Signal ?? • Signal is the communication channel used by the Linux Kernel to communicate with a process running in the user plane • This can be used by the kernel to kill a process, stop it, resume it, notify it of a timer expiry, etc… • Signals can also be sent by another process running in the user plane. Examples, • When the user presses Ctrl-c to terminate the running application, or Ctrl-z to stop it • When the user uses the command “bg” to resume a stopped application in the background, or “fg” to resume it in the foreground • When the user uses the “kill” command to terminate a running application • In all of these cases, a signal is sent to the destination application to achieve the required task • When sent by another user application, it is first passed to the kernel in a system call, which in turn passes it back to the desired process
  • 6. Signals • Signals are described in both Unix Systems and POSIX Standard • There are a table of signals. Each signal has, • Signal number • Signal name (starting with ‘SIG’) • Signals with numbers (1-31) are normal signals • Signals with numbers > 31 are called “Real Time Signals”
  • 7. Passing a Signal to a Process (kill Command) $ kill <pid> $ kill -<Signal number> <pid> $ kill <Signal name> <pid> • The kill command passes a signal to the desired process • Note that, despite that the command name is ‘kill’, it is used for all types of signals even those that have different purposes and not just used to kill processes • If no signal is specified, then the signal SIGTERM is assumed by default • Examples: $ kill -9 1185 $ kill SIGKILL 1185 Identical commands
  • 8. Other ways to “kill”
  • 9. Selecting Processes by name (killall Command) $ killall <Signal> <command name> • The command killall sends the desired signal to all processes running the specified command $ killall chrome • This is useful when you need to pick a process without searching for its pid • Also useful when you need to send the signal to all instances of the running program • If no signal is specified, SIGTERM is assumed • Example: $ killall -9 gedit (this sends a SIGKILL signal to all “gedit” instances)
  • 10. Selecting Processes by Other Criteria (pkill Command) $ pkill <signal> -u <username> $ pkill <siganal> -P <Parent process> $ pkill <signal> <pattern for command> $ pkill <signal> -t <Terminal name> • The pkill command sends the desired signal to processes that match different criteria • Examples: • Send a SIGTERM to all processes owned by user tom $ pkill -u tom • Send a SIGSTOP to all processes running under tty1 terminal $ pkill SIGSTOP -t tty1 • Send SIGTERM to all children of process with pid 1107 $ pkill –P 1107
  • 11. Killing GUI Processes with the Mouse (the xkill Command) $ xkill • The xkill command allows the user to select the process to kill with the mouse • Type the command, then click with the mouse on the UI of the process you want to kill
  • 12. Dealing with Hanging GUI Apps • If a GUI app is hanging, and you need to kill it but unable due to the hanging screen • get into a Linux virtual terminal via, [Ctrl] [Alt] [F1] • From the virtual terminal, issue the proper “kill” command $ killall -9 chrome • After you are done, get back to the tty-7 (for the X window) [Alt] [F7]
  • 14. Real time Signals • Those are the signals with numbers > 31 • They don’t have a pre-defined function, and it is left to the user/developer to use • Defined by the programmer • Guaranteed order of delivery
  • 16. Keyboard Hot keys • Some signals are triggered by the user by typing special hot- keys • When the kernel detects these hot-keys, it sends the proper signal to the running process (or process group) • Examples: • Ctrl-c triggers SIGINT • Ctrl-z triggers SIGTSTP • Ctrl- triggers SIGQUIT
  • 17. Request from another process • A process can trigger the kernel to send a signal to another process by issuing a system call • Examples for this is when the user issue the commands from the terminal $ kill (triggers sending the desired signal, SIGTERM by default) $ fg (triggers sending the signal SIGCONT) $ bg (triggers sending the signal SIGCONT) • A process can also trigger sending a signal to another process programmatically via some special function API
  • 18. A Hardware Event • Hardware events can trigger the kernel to send a signal to the proper process • An example of that, when the kernel detects a modem disconnection, it sends the signal SIGHUP to all processes using this session
  • 19. Death of a Related Process • When a process terminates, the kernel sends the following signals, • A SIGHUP is sent to all children processes to inform them about the death of their parent process • A SIGCHLD is sent to the parent of the terminated process to inform it about the death of a child process
  • 20. Errors and Exceptions • Some exceptions within the process triggers the kernel to send signals to the process, • Examples: • If the process tries to execute an illegal instruction, the kernel is triggered to send SIGILL signal to it • If the process suffers from a Floating Point Exception, the kernel sends it a SIGFPE • If the process tries to write to a pipe while the other end is not listening, the kernel sends it a SIGPIPE • If the process accesses a Null Pointer (or other memory exceptions), the kernel sends it SIGSEGV • If a process running in the background tries to read/write to the standard input/output, the kernel will send it a SIGTTIN/SIGTTOU • If the process exits on error using the abort(), the kernel will send it SIGABRT
  • 21. Notification By the Kernel • Sometimes, a process would ask the kernel for some notification when some event happens • Normally, the process will be waiting for this notification • The kernel delivers this notification via a signal • Examples: • The kernel will use the signal SIGALRM and SIGVTALRM to notify the process of a timer expiry • A process can ask the kernel for a notification whenever a file handler has been accessed
  • 23. Default Action • When a process receives a signal, the normal behavior is to execute the default action • Each signal has its own default action that is part of its description • Examples: • Some signals have the default action of termination (graceful termination). This is applicable for several signals such as SIGTERM, SIGPIPE, SIGUSR1, SIGUSR2, … • Some signals have the default action of termination with generation of a core dump (stack trace for further debugging). This action is useful for signals that indicate some error in the process operation such as SIGSEGV, SIGILL, SIGABRT, SIGQUIT … • Some signals have the default action of being ignored by the process such as SIGCHLD • Some signals does not allow the process to change its default action. This means that the default action is the only allowed action. This includes the SIGSTOP which force the process to stop (suspend) and SIGKILL which force the process to terminate immediately
  • 24. Ignoring a Signal • A process can set itself to ignore certain incoming signals, accordingly no action is performed when these signals are received • Some signals can not be ignored such as SIGSTOP, and SIGKILL
  • 25. Blocking a Signal • A process can set itself to block a certain set of signals • Blocking a signal means, keeping it in a queue for later handling (when the blocking is taken away) • This is used when the process is executing some code that should not be interrupted by the incoming signals • Every process has a mask of which signals to block • Only one signal of a certain type will be blocked (other instances will be dropped). • This last rule does not apply to real time signals (signals with numbers > 31) • Some signals can not be blocked (SIGSTOP and SIGKILL)
  • 26. Catching the Signal • A process can “catch the signal” before its default handler executes, and pass it to a special handler • This is specially useful for some of the signals that have their default action of being ignored (such as SIGCHLD) • Some signals can not be caught (SIGSTOP and SIGKILL)
  • 28. Hang-Up Signal (1) SIGHUP • The hang-up signal is used by the kernel to inform the processes running in a tty session when the session closes. This can be due to, • The modem for the session disconnects • The network connection used to connect to the machine breaks • It is commonly used to request daemon processes to re-read their configuration file • Default action for this signal for the process to terminate
  • 29. Interrupt Signal (2) SIGINT • Interrupt signal is triggered when the user uses the hot-key Ctrl-c • This causes the kernel to send SIGINT to the currently running process group • The default action for this signal is for the process to terminate
  • 30. Quit Signal (3) SIGQUIT • The quit signal is triggered by the user when he uses the hot- keys Ctrl- • This triggers the kernel to send SIGQUIT to all processes in the currently running process group • Default action is for the process to quit and generate a core dump file (to be used for debugging)
  • 31. Illegal Command Signal (4) SIGILL • The illegal command signal is triggered when the process program tries to execute an invalid instruction • This may occur in the case of memory corruption of the code area or in stack memory • Default action is to terminate and generate a core dump file
  • 32. Abort Signal (6) SIGABRT • The abort signal is sent by the kernel to the process when it calls the abort() function to indicate an erroneous exit of the program • The default action is to terminate and generate a core dump file
  • 33. Trap Signal (5) SIGTRAP • The trap signal is normally used with debuggers and program tracers
  • 34. Bus Error Signal (7) SIGBUS • The bus error signal is triggered by an error in the program in which an attempt was made to access memory incorrectly • This can be caused by alignment errors in memory access • The default action is to terminate and generate a core dump file
  • 35. Floating Point Exception (8) SIGFPE • The floating point exception signal is sent by the kernel to the process when it falls into an exception while running a floating point instruction • The default action is to terminate and generate a core dump file
  • 36. Kill Signal (9) SIGKILL • The process was explicitly killed by a request from a different process • The request is to kill the process immediately and forcibly without giving it a chance to clean-up • A process can not ignore, block, or catch this signal
  • 37. Stop Signals (17 &18) SIGSTOP & SIGTSTP • SIGTSTP (terminal Stop) is triggered by pressing Ctrl-z • This signal causes the process (or process group) to suspend operation • SIGSTOP has the same effect with the only difference that it can not be ignored/blocked/caught by the process while this is possible with SIGTSTP • Upon stopping due to either SIGSTOP & SIGTSTP, the process awaits SIGCONT to resume operation
  • 38. Terminate Signal (15) SIGTERM • The terminate signal is the default signal for the kill command when no signal is specified • The default action for SIGTERM is to gracefully terminate the process (process group) after clean up