🚩
Cyber Explained
  • WHOAMI
  • Technologies
    • Docker
      • Setup Docker
      • Terminology
      • Docker Hub
      • Docker Images
      • Docker Containers
      • Working with Containers
      • Virtualization vs Containerization
      • Nutshell
      • Troubleshoot
    • Android Application
      • Application File Structure
      • Layout and Resources for UI
      • Activities
      • Intents
      • Activity lifecycle and state
      • Implicit intents
    • Active Directory
      • Attacking Active Directory: 0 to 0.9
      • Resources
    • Kerberos
  • RED TEAMING
    • Attacking Kerberos
      • User Enum and Brute Force
      • AS-REP Roasting
      • Kerberoasting
    • MITRE ATT&CK
    • Resources
  • PenTesting
    • Android Pentesting
      • Re-Build App
      • Using Frida on Android without root
    • Web Pentesting
      • XSS
      • SQLi
      • Authentication Vulnerabilities
      • Session Security
      • CSRF
      • Path Traversal
      • File Inclusion
      • Business Logic Vulnerabilities
      • HTTP Host header attacks
      • SSRF
      • HTTP Request Smuggling
      • OS command injection
      • Access control vulnerabilities
    • OWASP Testing Guide
      • 1.0 Information Gathering
      • 2.0 Configuration and Deployment Management Testing
      • 3.0 Identity Management Testing
      • 4.0 Authentication Testing
      • 5.0 Authorization Testing
      • 6.0 Session Management Testing
      • 7.0 Input Validation Testing
      • 8.0 Testing for Error Handling
      • 9.0 Testing for Weak Cryptography
      • 10.0 Business Logic Testing
      • 11.0 Client-side Testing
      • 12.0 API Testing
  • Programming
    • Python
      • Hello World !
        • Variables and Data Types
        • Lists, Tuple, Sets and Dictionaries
        • If Statement
        • While Loops
        • For Loops
        • Functions
        • Classes and Objects
        • Creating Modules
        • Creating Packages
        • Exception Handling
      • System Pogramming
        • File Handling
        • OS Interaction with OS Library
        • Multithreading
        • Signals
        • Subprocess
        • Code Examples
      • Network Programming
        • Socket Programming
        • Packet Injection with Raw Sockets
        • SocketServer Framework
        • Packet Sniffing with Scapy
        • Creating a Web Server
        • Packet Injection with Scapy
        • Packet Sniffing with Raw Sockets
        • Programming with Scapy
  • Operating Systems
    • Windows*
    • Linux
      • System Structure
      • VI Text Editor
      • Working with the Linux Shell
      • Managing Users and Groups
      • Managing Files and Directories
  • Networks
    • Page 1
Powered by GitBook
On this page
  1. Programming
  2. Python
  3. System Pogramming

Signals

In simplistic terms, a signal is an event. A signal is used to interrupt the execution of a running function. The signals are always executed in the main Python thread.

Signal Functions

There are a number of functions implemented in the signal module. I will outline the must-know functions amongst them.

1. signal.alarm(time):

If you want to raise the SIGALRM signal then you can set the signal.alarm(time) function with the specified time in seconds. If the time is set to 0, then it disables the alarm Setting a new alarm cancels any previously scheduled alarms.

2. signal.pause() The process sleeps until a signal is received. And then the signal handler is called.

3. signal.raise_signal(number of signal): It sends a signal to the calling process

4. signal.setitimer(which, seconds, interval) This function accepts float number of seconds which we can use to raise a signal. Also after that, for each interval, the signal is sent to the process.

5. signal.siginterrupt(signalnum, flag): It changes system call restart behaviour. If the flag is False then the system calls are restarted when they are interrupted by signal signalnum If the flag is True then the system calls are interrupted

6. signal.getsignal(signalnum)

It takes the signal and returns the handler.

7. signal.signal(signalnum, handler): Lastly and most importantly, I wanted to cover the functional signal() This function sets the handler whenever the signal signalnum is received. The handler is essentially a Python function/callable that takes in either two of the arguments:

  • The signal number

  • Current stack frame (or signal.SIG_IGN or signal.SIG_DFL) as arguments.

In a multi-threaded application, it can only be called from the main thread

PreviousMultithreadingNextSubprocess

Last updated 3 years ago