Advance Innovation Centre
  • AIC Knowledge @ EEC for All
  • 😎Logical Thinking
    • Karel Robot
    • Code to Flowchart
    • Play with Docker
    • CNX Software
  • MCU & Interfacing with Infineon PSOCâ„Ē
    • Basic MCU Interfacing
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
      • PSoCâ„Ē 6S2 Peripherals Interfacing (GPIO)
        • Hello World and LED Blinking
        • GPIO Principles
        • PSoCâ„Ē 6S2 GPIO-HAL LED Blink Lab
        • PSoCâ„Ē 6S2 GPIO-PDL LED Blink Lab
        • Button "Bounce" Principles
          • Push/Pull Button to Turn ON/OFF LED via HAL
          • Push/Pull Button to Turn ON/OFF LED via PDL
          • GPIO Button Interrupt via HAL
          • GPIO Button Interrupt via PDL
        • GPIO variables & functions
      • PSoCâ„Ē 6S2 Peripherals Interfacing (ADC, PWM)
        • PSoCâ„Ē 6S2 SAR ADC
          • ADC Principles
          • PSoCâ„Ē 6S2 with ADC Labs
            • Reading potentiometer sensor value via an ADC HAL
            • Reading potentiometer sensor value via an ADC PDL
        • PSoCâ„Ē 6S2 PWM & TCPWM
          • PWM Principles
          • PSoCâ„Ē 6S2 for PMW Function Labs
            • LED Brightness using PWM via HAL
            • LED Brightness using PWM via PDL
    • Sensor Interfacing and HMI
      • OLED Display
        • OLED Display Principles
        • Calling BDH’s OLED functions
        • Display ADC via Potentiometer on OLED
      • BDH Shell
        • Shell Principles
        • LED Blinking and CAPSENSE via BDH Shell
        • Adding "History" command
        • Adding "Reboot" command
        • CAPSENSE Button and Slider
          • CAPSENSE Button and Slider with Capsense Tuner
          • CAPSENSE Button and Slider using FreeRTOS
    • Serial Communication & Visualization
      • UART, I2C, SPI Communication via Infineon PSoCâ„Ē6
      • BMX160 Sensor Communication via Infineon PSoCâ„Ē6
        • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
        • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
        • Motion Sensors GUI Integration via Serial Studio
    • IoT Connectivity & Data Analytics via Node-Red
      • Node-Red Installation
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • Edge AI on PSoCâ„Ē
      • Machine Learning on PSoCâ„Ē6 via Edge-Impulse
    • Infineon PSoCâ„Ē Troubleshooting
  • IoT Development with Infineon PSOCâ„Ē & BDH Platform
    • PSoCâ„Ē IoT Development Kit
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
        • Hello World and LED Blinking
    • IoT Connectivity
      • Node-Red Installation
      • Controlling PSoCâ„Ē LED using MQTT
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • BDH IoT Connectivity
    • WireLinXâ„Ē IoT PLC
    • BDH X-Brain Data Analytics
      • PSoC6 Data Collection to CSV log file
    • Data Visualization
      • āļŠāļĢāđ‰āļēāļ‡ Dashboard āļ”āđ‰āļ§āļĒ Looker Studio
  • ðŸ–ĨïļOperation Systems
    • Prerequisites
      • Guideline from Ubuntu
        • Ubuntu and VSCode on WSL2
      • āļ•āļīāļ”āļ•āļąāđ‰āļ‡ WSL 2
      • Run Ubuntu on VirtualBox7
    • Zero to Linux Hero
      • Computer OS Architecture
      • Anatomy of Linux System
        • UNIX/Linux History
        • UNIX/Linux Evolution
        • GNU Project
        • Linux OS Architecture
        • Command Line Interface (CLI)
          • Basic Commands
          • 😎Level up your Linux Shell
          • File & Dir. Commands
          • Searching Commands
          • 😎ChatGPT-based Terminal
          • SysAdmin Commands
          • Network Commands
          • Hacker Commands
        • Busybox
        • Shell Script
          • Awk Script
          • Bash Shell Script
            • Bash Snippets
            • Bash Useful Examples
      • Anatomy of Linux Kernel
        • Linux Kernel Principles
        • Linux Environment for Developer
      • Anatomy of Embedded Linux
        • Embedded Linux
        • Host & Target
        • Cross Toolchains
        • Bootloader
        • Building Embedded Linux
    • Linux OS Dev. Engineer
      • Process Management
        • Process Basic
        • Process State
        • Basic Process Mgmt. Commands
        • Advance Process Mgmt. Commands
        • Process API Programming
      • IPC
        • IPC Anatomy
        • Signal Programming
        • Pipe Programming
        • FIFO Programming
        • Msg. Queue Programming
          • System V
        • Share Memory Programming
          • System V
        • Socket Programming
      • POSIX Threads
        • Multi-tasking Basic
        • POSIX Thread Anatomy
        • Threading Programming
      • Applied IPC
        • Remote Commander
        • Multi-Remote Commanders
      • Process Synchronization
        • Mutex Programming
        • Semaphore Programming
      • Applied IPC with Semaphore
  • ⌚Embedded Systems Development
    • Introduction to ESD
      • Why's ESD?
      • What it use for?
      • How it works?
    • Enbedded System Development via PSoC6
      • Basic MCU Interfacing
        • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
        • Development Environment Preparation
        • PSoCâ„Ē 6S2 Peripherals Interfacing (GPIO)
          • Hello World and LED Blinking
          • GPIO Principles
          • PSoCâ„Ē 6S2 GPIO-HAL LED Blink Lab
          • PSoCâ„Ē 6S2 GPIO-PDL LED Blink Lab
          • Button "Bounce" Principles
            • Push/Pull Button to Turn ON/OFF LED via HAL
            • Push/Pull Button to Turn ON/OFF LED via PDL
            • GPIO Button Interrupt via HAL
            • GPIO Button Interrupt via PDL
          • GPIO variables & functions
        • PSoCâ„Ē 6S2 Peripherals Interfacing (ADC, PWM)
          • PSoCâ„Ē 6S2 SAR ADC
            • ADC Principles
            • PSoCâ„Ē 6S2 with ADC Labs
              • Reading potentiometer sensor value via an ADC HAL
              • Reading potentiometer sensor value via an ADC PDL
          • PSoCâ„Ē 6S2 PWM & TCPWM
            • PWM Principles
            • PSoCâ„Ē 6S2 for PMW Function Labs
              • LED Brightness using PWM via HAL
              • LED Brightness using PWM via PDL
      • Sensor Interfacing and HMI
        • OLED Display
          • OLED Display Principles
          • Calling BDH’s OLED functions
          • Display ADC via Potentiometer on OLED
        • BDH Shell
          • Shell Principles
          • LED Blinking and CAPSENSE via BDH Shell
          • Adding "History" command
          • Adding "Reboot" command
          • CAPSENSE Button and Slider
            • CAPSENSE Button and Slider with Capsense Tuner
            • CAPSENSE Button and Slider using FreeRTOS
      • Serial Communication & Visualization
        • UART, I2C, SPI Communication via Infineon PSoCâ„Ē6
        • BMX160 Sensor Communication via Infineon PSoCâ„Ē6
          • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
          • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
          • Motion Sensors GUI Integration via Serial Studio
    • Edge Computing and IoT Connectivity
    • Cloud-Based Data Analytics and Digital Twin
    • Edge Vision AI
    • Resources
      • Basic Hardware and Firmware
        • Environment Preparation
          • āļāļēāļĢāļ•āļīāļ”āļ•āļąāđ‰āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄ Arduino IDE
            • āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāđ€āļĢāļīāđˆāļĄāļ•āđ‰āļ™āđƒāļŠāđ‰āļ‡āļēāļ™ Arduino IDE
          • āļāļēāļĢāļ•āļīāļ”āļ•āļąāđ‰āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄāļŠāļģāļŦāļĢāļąāļšāđƒāļŠāđ‰āļ‡āļēāļ™āđ€āļ„āļĢāļ·āđˆāļ­āļ‡āļĄāļ·āļ­āļ§āļąāļ” NI MyDAQ
            • āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāļ•āļąāđ‰āļ‡āļ„āđˆāļēāđƒāļŠāđ‰ Digital Multimeter -NI ELVISmx
            • āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāļ•āļąāđ‰āļ‡āļ„āđˆāļēāđƒāļŠāđ‰ Oscilloscope-NI ELVISmx
          • āļ•āļīāļ”āļ•āļąāđ‰āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄ KingstVIS
        • Basic measurement
          • Basic Digital and Analog I/O
            • LAB: Basic Digital Input/Output
            • LAB: Basic Analog Input/Output
          • Waveform
            • LAB: Oscilloscope
            • LAB: Oscilloscope and Function Generator
            • LAB: Pulse Width Modulation (PWM)
              • Homework
        • Interfacing and Communication
          • LAB: UART, RS485, RS232 Protocol
          • LAB: I2C Protocol
            • HOMEWORK
          • LAB: SPI Protocol
      • IoT Connectivity
        • Example: IoT with MQTT on Node-red
        • Data logger
        • LAB: Data Visualization
  • 🛠ïļC/C++ for Embedded Programming
    • Development Environment Preparation
      • āļ•āļīāļ”āļ•āļąāđ‰āļ‡ WSL 2
      • āļ•āļīāļ”āļ•āļąāđ‰āļ‡ Ubuntu environment
      • āļ•āļīāļ”āļ•āļąāđ‰āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄ Visual Studio Code
      • āļāļēāļĢāđ€āļŠāļ·āđˆāļ­āļĄāļ•āđˆāļ­ Virtual studio code āđ€āļ‚āđ‰āļēāļāļąāļš WSL
      • āļ•āļīāļ”āļ•āļąāđ‰āļ‡ docker on WSL
    • Principle C/C++ Programming
      • Get started with C++
      • Makefile
        • Makefile Examples
      • Compiling and running
        • How to create a program that you can enter inputs.
          • Lab 1 Exercise
      • Arguments
        • Command line arguments in C and C++
      • signed and unsigned data types
      • Variable and Operator
      • If and If else
      • Loop, Infinite loop, and flag
        • Loop and Flag exercise
      • Array
        • Get to know with arrays
        • Implement example
      • Vector
    • Object Oriented Programming (OOP) in C++
      • Class and Object
      • Encapsulation and Abstraction
      • Polymorphism and Inheritance
    • C/C++ Preprocessing
      • Macro
        • Quiz Macro
      • File Inclusion
      • Conditional Compilation
      • Pragma directive
        • Quiz Pragma
    • String in C++
      • Concatenation
      • Split
    • Type conversions for C/C++
      • Conversion using Cast operator
    • Error handling
    • Data logger
      • āļāļēāļĢāļŠāļĢāđ‰āļēāļ‡āđ„āļŸāļĨāđŒāđāļĨāļ°āđ€āļ‚āļĩāļĒāļ™āđ„āļŸāļĨāđŒ
      • āļāļēāļĢāļ­āđˆāļēāļ™āđ„āļŸāļĨāđŒ
      • āļāļēāļĢāđ€āļāđ‡āļšāļ‚āđ‰āļ­āļĄāļđāļĨāļāļąāļšTime stamp
    • High performance programing
      • Multi-task and Multi-thread
        • Multi-threading example
      • Mutex
      • Queue
      • OpenCV
    • C/C++ Techniques
      • Makefile in action
      • Object Oriented Programming (OOP) in C++
        • Class and Object
        • Encapsulation and Abstraction
        • Polymorphism and Inheritance
      • C/C++ Preprocessing
        • Macro
          • Quiz Macro
        • File Inclusion
        • Conditional Compilation
        • Pragma directive
          • Quiz Pragma
      • Binary, Octal and Hexadecimal Numbers
      • Array and properties of an array
        • Get to know with arrays
        • Implement example
      • What's next?
  • ðŸĪ–Artificial Intelligence (AI)
    • VAMStack Design House, BUU
    • Data Analytics
      • Data cleansing
      • Data analytics
      • Data analytic exercise
    • Machine Learning
      • Neural Network Layers
      • Machine learning type
      • Dataset
      • Using Edge Impulse for AI Model
    • Basic Image Processing
      • Computer Vision using Python Language
        • Installation
        • Computer Vision Basics
          • Pixel and Color
          • Draw image
          • Basic Image processing
          • Morphology Transformations
          • Gaussian blur
          • Simple Thresholding
          • Contour
          • Canny edge detection
        • Case Study
          • Coin counting
          • Color detection & tracking
        • VAM_CV SDK
  • ⚙ïļFPGA Design and Development
    • Verilog HDL via Vivado IDE
      • LAB1: Setting Environment and Create Project
        • Create Vivado Project
      • LAB2: Hardware Description Language Work Flow
        • Simulation code
      • LAB3: Design HDL Project
        • Top Level Design
        • Top-level Simulation
      • LAB4: Asynchronous VS Synchronous Circuit
        • Simulation Synchronous counter
    • C/C++ Programming on Ultra96v2 FPGA Board
      • Application C/C++ on Ultra96v2 Part 1
        • Design Overview
        • Step 1 - Burn the image to SD card
        • Step 2 - Bring up Ultra96v2
        • Step 3 - Installing the Vitis-AI runtime packages
      • Application C/C++ on Ultra96v2 Part 2
        • STEP 1 : Setting auto boot Wifi
        • STEP 2 : How to working on Embedded
        • STEP 3 : How to run the test code
  • ðŸĪ–Robotics
    • Dobot Magician
      • Instruction of Dobot
      • Software Download
      • Basically of Program
        • Teaching and Playback
        • Write and Draw
        • LaserEngraving
        • 3D Printer
    • Robotino
      • Software Download
        • Robotino View
        • Robotino SIM
      • Charging
      • Connecting
      • Follow Line example
        • Basic block in Follow Line
    • RaspBlock
      • Get Started with Raspblock
  • ðŸšĐSpecial Topics
    • Node-Red
      • Set up Raspberry Pi
      • Install node red in Raspberry Pi
      • Get started with Node Red
        • Open node-red
        • Turn off node red
        • Install Dashboard on Node-red
        • Use node red to show message
        • Using Ultrasonic sensor with node-red
    • IoT Cloud
      • Overview
        • How do they work?
          • Basic Knowlege
      • Installations
        • Install Docker
        • Install Mosquitto Broker
        • Install InfluxDB
        • Install Telegraf
        • Install Grafana
      • Get Sensor Value and Send to MQTT
        • Connect ESP3266 to sensor
        • Connect ESP3266 to MQTT
      • Integration
    • Senses IoT
      • SENSES IoT Platform
      • LAB8: MCU send data to IoT platform
    • CrowPi Dev Kit
      • Raspberry Pi with CrowPi
      • Remote to Raspberry Pi
      • Cross-Compile
        • Lab 1: Programming and cross complier
      • Hardware and Interfaces Usage CLI
        • LAB: Usage GPIO via CLI
        • LAB: Scan I2C bus via CLI
      • Python library for Crow Pi
      • wiringPi library (C) for CrowPi
        • Lab2: Crowpi and sensors
    • LVGL Development
      • LVGL - Light and Versatile Embedded Graphics Library
        • Setting program for LVGL Simulator
        • Get started with LVGL simulator
        • Example Library of LVGL
        • Create your own screen
          • Exercise
        • Style
          • Exercise
        • Event
    • Docker OS
      • Docker OS Part 1
        • Part 1 : Installation
        • Part 2 : Basic Docker OS and Linux CLI
      • Docker OS Part 2
        • Part 1 : Docker communication
        • Part 2 : Docker compose
      • Application Gstreamer on devcontainer
        • STEP 1 : Setting gstreamer environment
        • STEP 2 : Create the Gstreamer element on template
        • STEP 3 : Testing and application on your gst element
  • ðŸĪŸRecommended by AIC
    • Skill Roadmap
      • Embedded Engineer
      • Developer
    • Hardware Programming
    • Embedded Programming
    • General-propose Programming
    • Algorithmica
    • Thai Expert Knowledge
    • RT-Thread University Program
      • Infineon PSoC6
      • Kernel
        • Kernel Basics
        • Thread Management
        • Clock Management
        • Inter-thread synchronization
        • Inter-thread communication
        • Memory Management
        • Interrupt Management
        • Kernel porting
        • Atomic Operations
        • RT-Thread SMP
        • Kernel API Changelog
      • Tools
      • Devices & Drivers
        • SENSOR Devices
        • Touch Equipment
        • CRYPTO Devices
        • AUDIO Devices
        • Pulse Encoder Devices
      • Components
        • C Library (libc)
        • ISO/ANSI C Standard
        • POSIX Standard
          • FILE (File IO)
          • Pthread
          • Timer
          • IPC Semaphore
          • IPC Message Queues
          • Dynamic Modules
        • Network Components
          • FinSH Console
          • FAL: Flash Abstraction Layer
          • Virtual File System
          • tmpfs: temporary file system
          • ulog log
          • utest testing framework
          • Power Management
          • RT-Link
        • Software Packages
          • Internet of Things
            • MQTT-umqtt
            • Telnet
          • Tools
            • SystemView
            • SEGGER_RTT
          • LVGL Manual
            • Touch Screen Driver
      • Demo
        • Infineon Gateway
        • Handwriting Recognition (MNIST)
        • Object Detection (Darknet)
        • ROS using RT-Thread
        • Control the car using RT-Thread
        • LiDAR via RT-Thread
        • Detection via RT-Thread and ROS
        • Sensor Driver Development Guide
Powered by GitBook

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University

On this page

Was this helpful?

  1. Operation Systems
  2. Linux OS Dev. Engineer
  3. IPC

Signal Programming

āļāļēāļĢāļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ (signal) āļ–āļ·āļ­āļ§āđˆāļēāđ€āļ›āđ‡āļ™āļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨāļ‚āļąāđ‰āļ™āļžāļ·āđ‰āļ™āļāļēāļ™āļĢāļ°āļŦāļ§āđˆāļēāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ āļēāļĒāđƒāļ•āđ‰āļĢāļ°āļšāļšāļ›āļāļīāļšāļąāļ•āļīāļāļēāļĢāļĨāļĩāļ™āļļāļāļ‹āđŒ āđ‚āļ”āļĒāđ‚āļ›āļĢāđ€āļ‹āļŠāļŦāļ™āļķāđˆāļ‡āļˆāļ°āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđ„āļ›āļĒāļąāļ‡āļ­āļĩāļāđ‚āļ›āļĢāđ€āļ‹āļŠāļŦāļ™āļķāđˆāļ‡ āđ€āļĄāļ·āđˆāļ­āļ­āļĩāļāđ‚āļ›āļĢāđ€āļ‹āļŠāļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļšāļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļ–āļđāļāđāļ—āļĢāļāđ€āļ‚āđ‰āļēāļĄāļē (interrupt) āļĄāļąāļ™āļāđ‡āļˆāļ°āļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāļ–āļđāļāļ•āļąāđ‰āļ‡āđ€āļ­āļēāđ„āļ§āđ‰āļ—āļąāļ™āļ—āļĩ āļ‹āļķāđˆāļ‡āđ€āļĄāļ·āđˆāļ­āđ€āļĢāļīāđˆāļĄāđāļĢāļāļ‚āļ­āļ‡āļāļēāļĢāļ™āļģāļŠāļąāļāļāļēāļ“āļĄāļēāđƒāļŠāđ‰āļ™āļąāđ‰āļ™ āļˆāļ°āđ€āļ›āđ‡āļ™āđ€āļžāļĩāļĒāļ‡āļĢāļđāļ›āđāļšāļšāļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāđ„āļĄāđˆāđ„āļ”āđ‰āđāļĒāļāđāļĒāļ°āļŠāļ™āļīāļ”āļŦāļĢāļ·āļ­āļ›āļĢāļ°āđ€āļ āļ—āļ‚āļ­āļ‡āļŠāļąāļāļāļēāļ“āļ­āļ°āđ„āļĢāļĄāļēāļāļĄāļēāļĒāđāļ•āđˆāđƒāļ™āļ›āļąāļˆāļˆāļļāļšāļąāļ™āļāļēāļĢāļžāļąāļ’āļ™āļēāļ‚āļ­āļ‡āļĢāļ°āļšāļšāļ›āļāļīāļšāļąāļ•āļīāļāļēāļĢāļĨāļĩāļ™āļļāļāļ‹āđŒāļĄāļĩāļ„āļ§āļēāļĄāļ‹āļąāļšāļ‹āđ‰āļ­āļ™āļĄāļēāļāļ‚āļķāđ‰āļ™ āļĢāļ§āļĄāļ—āļąāđ‰āļ‡āļāļēāļĢāļŠāļ·āđˆāļ­āļŠāļēāļĢāļĢāļ°āļŦāļ§āđˆāļēāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļāđ‡āļ•āđ‰āļ­āļ‡āļāļēāļĢāđ€āļ‡āļ·āđˆāļ­āļ™āđ„āļ‚āļ—āļĩāđˆāļŦāļĨāļēāļāļŦāļĨāļēāļĒāļĄāļēāļāļ‚āļķāđ‰āļ™āđ€āļŠāđˆāļ™āļāļąāļ™ āļˆāļķāļ‡āļ—āļģāđƒāļŦāđ‰āļĄāļĩāļāļēāļĢāļāļģāļŦāļ™āļ”āļ›āļĢāļ°āđ€āļ āļ—āļ‚āļ­āļ‡āļŠāļąāļāļāļēāļ“ (signal type) āļ‚āļķāđ‰āļ™āļĄāļēāđ‚āļ”āļĒāļĄāļĩāļŠāļ™āļīāļ”āđ€āļ›āđ‡āļ™āđ€āļĨāļ‚āļˆāļģāļ™āļ§āļ™āđ€āļ•āđ‡āļĄ (integer value) āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ€āļŠāđˆāļ™ āđ€āļĨāļ‚ 15 (SIGTERM) āđāļ—āļ™āļŠāļąāļāļāļēāļ“āļŠāļīāđ‰āļ™āļŠāļļāļ”āļāļēāļĢāļ—āļģāļ‡āļēāļ™ (Terminate) āļ‹āļķāđˆāļ‡āļŦāļĄāļēāļĒāđ€āļĨāļ‚āļŠāļąāļāļāļēāļ“āļ•āđˆāļēāļ‡āđ†āļˆāļ°āļ–āļđāļāļāļģāļŦāļ™āļ”āļ­āļĒāļđāđˆāđƒāļ™āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ signal.h

1) SIGHUP

2) SIGINT

3) SIGQUIT

4) SIGILL

5) SIGTRAP

6) SIGABRT

7) SIGBUS

8) SIGFPE

9) SIGKILL

10) SIGUSR1

11) SIGSEGV

12) SIGUSR2

13) SIGPIPE

14) SIGALRM

15) SIGTERM

16) SIGSTKFLT

17) SIGCHLD

18) SIGCONT

19) SIGSTOP

20) SIGTSTP

21) SIGTTIN

22) SIGTTOU

23) SIGCONT

24) SIGXCPU

25) SIGXFSZ

26) SIGVTALRM

27) SIGPROF

28) SIGWINCH

29) SIGIO

30) SIGPWR

31) SIGSYS

34) SIGRTMIN

35) SIGRTMIN+1

36) SIGRTMIN+2

37) SIGRTMIN+3

38) SIGRTMIN+4

39) SIGRTMIN+5

40) SIGRTMIN+6

41) SIGRTMIN+7

42) SIGRTMIN+8

43) SIGRTMIN+9

44) SIGRTMIN+10

45) SIGRTMIN+11

46) SIGRTMIN+12

47) SIGRTMIN+13

48) SIGRTMIN+14

49) SIGRTMIN+15

50) SIGRTMAX-14

51) SIGRTMAX-13

52) SIGRTMAX-12

53) SIGRTMAX-11

54) SIGRTMAX-10

55) SIGRTMAX-9

56) SIGRTMAX-8

57) SIGRTMAX-7

58) SIGRTMAX-6

59) SIGRTMAX-5

60) SIGRTMAX-4

61) SIGRTMAX-3

62) SIGRTMAX-2

63) SIGRTMAX-1

64) SIGRTMAX

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āļœāđˆāļēāļ™āļ„āļĩāļĒāđŒāļšāļ­āļĢāđŒāļ”

Ctrl-C

āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ INT (SIGINT) āđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ—āļĩāđˆāļ—āļģāļ‡āļēāļ™āļ­āļĒāļđāđˆāļĒāļļāļ•āļīāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ—āļąāļ™āļ—āļĩ

Ctrl-Z

āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ TSTP (SIGTSTP) āđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ—āļĩāđˆāļ—āļģāļ‡āļēāļ™āļ­āļĒāļđāđˆāđƒāļŦāđ‰āļŦāļĒāļļāļ”āļŠāļąāđˆāļ§āļ„āļĢāļēāļ§

Ctrl-\

āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ ABRT (SIGABRT) āđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ—āļĩāđˆāļ—āļģāļ‡āļēāļ™āļ­āļĒāļđāđˆāđƒāļŦāđ‰āļĒāļļāļ•āļīāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ™āļąāđ‰āļ™āļ—āļąāļ™āļ—āļĩ āđ€āļŦāļĄāļ·āļ­āļ™ Ctrl-C āđāļ•āđˆāđ€āļ›āđ‡āļ™āļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāļ”āļĩāļāļ§āđˆāļēāļ„āļ·āļ­āļŠāļēāļĄāļēāļĢāļ–āđāļāđ‰āđ„āļ‚āđ„āļ”āđ‰

āļ™āļ­āļāļˆāļēāļāļ™āļąāđ‰āļ™āļˆāļ°āļĄāļĩāļāļēāļĢāđ€āļĢāļĩāļĒāļāđƒāļŠāđ‰āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ kill() āđ€āļžāļ·āđˆāļ­āļ—āļģāļāļēāļĢāļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āļ­āļ­āļāđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ›āļĨāļēāļĒāļ—āļēāļ‡ āđ‚āļ”āļĒāļ—āļĩāđˆāđ‚āļ›āļĢāđ€āļ‹āļŠāļĢāļąāļšāļ›āļĨāļēāļĒāļ—āļēāļ‡āļˆāļ°āļĄāļĩāļāļēāļĢāļāļģāļŦāļ™āļ”āđ„āļ§āđ‰āļ§āđˆāļēāļ–āđ‰āļēāđ„āļ”āđ‰āļĢāļąāļšāļŠāļąāļāļāļēāļ“āļŦāļĄāļēāļĒāđ€āļĨāļ‚āļ™āļĩāđ‰ āļāđ‡āđƒāļŦāđ‰āļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāđ€āļĢāļĩāļĒāļāļŸāļąāļ‡āļāđŒāļŠāļąāļ™āļ—āļĩāđˆāļāļģāļŦāļ™āļ”āđ„āļ§āđ‰āļ•āđˆāļ­āđ„āļ› āļ”āđ‰āļ§āļĒāļāļēāļĢāđ€āļĢāļĩāļĒāļāđƒāļŠāđ‰āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ signal() āļ­āļĒāđˆāļēāļ‡āđ„āļĢāļāđ‡āļ•āļēāļĄāđ‚āļ›āļĢāđ€āļ‹āļŠāļ•āđˆāļēāļ‡āđ†āļ—āļĩāđˆāļ­āļĒāļđāđˆāļ āļēāļĒāđƒāļ•āđ‰āļœāļđāđ‰āđƒāļŠāđ‰āļ„āļ™āđ€āļ”āļĩāļĒāļ§āļāļąāļ™ āļˆāļ°āļŠāļēāļĄāļēāļĢāļ–āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āļ–āļķāļ‡āļāļąāļ™āđ„āļ”āđ‰ āđāļ•āđˆāđ„āļĄāđˆāļŠāļēāļĄāļēāļĢāļ–āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ­āļ·āđˆāļ™āđ†āļ‚āļ­āļ‡āļœāļđāđ‰āđƒāļŠāđ‰āļ„āļ™āļ­āļ·āđˆāļ™āđ„āļ”āđ‰ āļĒāļāđ€āļ§āđ‰āļ™āđ‚āļ›āļĢāđ€āļ‹āļŠāļ‚āļ­āļ‡ superuser āđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™

āļŸāļąāļ‡āļāđŒāļŠāļąāļ™āđāļĨāļ°āļ•āļąāļ§āđāļ›āļĢāļ—āļĩāđˆāđ€āļāļĩāđˆāļĒāļ§āļ‚āđ‰āļ­āļ‡

  • āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ void signal(int sig_type, void (*sig_handler)(int signal_type))

    • sig_type āđāļ—āļ™āļ„āđˆāļēāļ‚āļ­āļ‡āļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļˆāļ°āļ•āļĢāļ§āļˆāļˆāļąāļš (āļ”āļđāļˆāļēāļāđ„āļŸāļĨāđŒ signal.h)

      • sig_handles āđāļ—āļ™āļ„āđˆāļēāļ•āļąāļ§āļŠāļĩāđ‰ (pointer) āđ„āļ›āļĒāļąāļ‡āļŸāļąāļ‡āļāđŒāļŠāļąāļ™āļ—āļĩāđˆāļŠāļĢāđ‰āļēāļ‡āļ‚āļķāđ‰āļ™āļĄāļēāđ€āļžāļ·āđˆāļ­āļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāđ€āļĄāļ·āđˆāļ­āđ„āļ”āđ‰āļĢāļąāļšāļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļ•āļĢāļ§āļˆāļˆāļąāļšāđ„āļ”āđ‰

  • āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ int kill (pid_t dest_pid, int sig_type)

    • āđ€āļ›āđ‡āļ™āļŸāļąāļ‡āļāđŒāļŠāļąāļ™āļ—āļĩāđˆāđƒāļŠāđ‰āđƒāļ™āļāļēāļĢāļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļ•āđ‰āļ­āļ‡āļāļēāļĢ (sig_type) āđ„āļ›āļĒāļąāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļ›āļĨāļēāļĒāļ—āļēāļ‡ (dest_pid) āļ™āļ­āļāļˆāļēāļāļ™āļąāđ‰āļ™āļ–āđ‰āļēāļĄāļĩāļāļēāļĢāļāļģāļŦāļ™āļ”āļ„āđˆāļē dest_pid āđ€āļ›āđ‡āļ™ 0 āļˆāļ°āļŦāļĄāļēāļĒāļ–āļķāļ‡āļāļēāļĢāļŠāđˆāļ‡āđ„āļ›āļĒāļąāļ‡āļ—āļļāļāđ‚āļ›āļĢāđ€āļ‹āļŠāļ‚āļ­āļ‡āļœāļđāđ‰āđƒāļŠāđ‰āđ€āļ”āļĩāļĒāļ§āļāļąāļ™ āđāļ•āđˆāļ–āđ‰āļēāļāļģāļŦāļ™āļ”āļ„āđˆāļē dest_pid āđ€āļ›āđ‡āļ™ -1 āđ€āļĄāļ·āđˆāļ­āđƒāļ”āļˆāļ°āļŦāļĄāļēāļĒāļ–āļķāļ‡āļāļēāļĢāļŠāđˆāļ‡āđ„āļ›āļĒāļąāļ‡āļ—āļļāļāđ‚āļ›āļĢāđ€āļ‹āļŠāđƒāļ™āļĢāļ°āļšāļš (āđāļ•āđˆāđƒāļŠāđ‰āđ„āļ”āđ‰āđ€āļ‰āļžāļēāļ°āđ€āļ›āđ‡āļ™ superuser āđ€āļ—āđˆāļēāļ™āļąāđ‰āļ™)

  • āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ void raise (int sig_type)

    • āđƒāļŠāđ‰āđƒāļ™āļāļĢāļ“āļĩāļ—āļĩāđˆāļ•āđ‰āļ­āļ‡āļāļēāļĢāļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ (sig_type) āđƒāļŦāđ‰āļ•āļąāļ§āđ€āļ­āļ‡

āļŠāļīāđˆāļ‡āļ—āļĩāđˆāļ„āļ§āļĢāļĢāļđāđ‰

  • āđ‚āļ›āļĢāđ€āļ‹āļŠāļˆāļ°āđ„āļ”āđ‰āļĢāļąāļšāļŠāļąāļāļāļēāļ“āđ„āļ”āđ‰āļ—āļąāđ‰āļ‡āļœāđˆāļēāļ™āđ‚āļ›āļĢāđ€āļ‹āļŠāđƒāļ™āļāļĨāļļāđˆāļĄāđ€āļ”āļĩāļĒāļ§āļāļąāļ™āļ‚āļ­āļ‡āļœāļđāđ‰āđƒāļŠāđ‰āļ™āļąāđ‰āļ™āļŠāđˆāļ‡āļĄāļēāļŦāļĢāļ·āļ­āļœāļđāđ‰āđƒāļŠāđ‰āđƒāļ™āļĢāļ°āļ”āļąāļš superuser āđ€āļ›āđ‡āļ™āļœāļđāđ‰āļŠāđˆāļ‡āļĄāļēāđƒāļŦāđ‰āđ€āļ­āļ‡

  • āļŠāļ™āļīāļ”āļ‚āļ­āļ‡āļŠāļąāļāļāļēāļ“āđāļĨāļ°āļŠāļ·āđˆāļ­āļ‚āļ­āļ‡āļŠāļąāļāļāļēāļ“āļ–āļđāļāļāļģāļŦāļ™āļ”āļ­āļĒāļđāđˆāđƒāļ™āđ„āļŸāļĨāđŒ signal.h

  • āļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļ–āļđāļāļŠāđˆāļ‡āđ„āļ›āļˆāļ°āđ„āļĄāđˆāļŠāļēāļĄāļēāļĢāļ–āļ–āļđāļāđ€āļāđ‡āļšāđ€āļ‚āđ‰āļēāļ„āļīāļ§āđ„āļ”āđ‰

  • āļ•āļąāļ§āļˆāļąāļ”āļāļēāļĢāļ—āļĩāđˆāđƒāļŠāđ‰āđƒāļ™āļāļēāļĢāļŠāļīāđ‰āļ™āļŠāļļāļ”āđ‚āļ›āļĢāđ€āļ‹āļŠāļ„āļ·āļ­ SIG_DFL āđāļĨāļ° SIG_IGN āđƒāļ™āļāļĢāļ“āļĩāļ•āđ‰āļ­āļ‡āļāļēāļĢāđ€āļžāļīāļāđ€āļ‰āļĒāļ•āđˆāļ­āļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāđ€āļ‚āđ‰āļēāļĄāļē āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ€āļŠāđˆāļ™signal (SIGINT, SIG_IGN);

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 1

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāļāļģāļŦāļ™āļ”āļŸāļąāļ‡āļāđŒāļŠāļąāļ™āļ—āļĩāđˆāļˆāļ°āđƒāļŦāđ‰āļ”āļģāđ€āļ™āļīāļ™āļāļēāļĢāđ€āļĄāļ·āđˆāļ­āļ•āļĢāļ§āļˆāļˆāļąāļšāļŠāļąāļāļāļēāļ“āļ—āļĩāđˆāļāļģāļŦāļ™āļ”āđ„āļ§āđ‰ āļ‹āļķāđˆāļ‡āđƒāļ™āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ™āļĩāđ‰āļˆāļ°āļ•āļĢāļ§āļˆāļŠāļ­āļšāļŠāļąāļāļāļēāļ“āļŦāļĄāļēāļĒāđ€āļĨāļ‚ 2 (SIGINT)

// signal1.c
#include<stdio.h>
#include<signal.h>
#include<unistd.h>

void signalHandler(int signo) {
	if (signo == SIGINT)
		printf(" received SIGINT\n");
}

int main(void) {
	printf("My pid is %d.\n", getpid());
	if (signal(SIGINT, signalHandler) == SIG_ERR)
		printf("\n Can't catch SIGINT\n");
// A long long wait so that we can easily issue a signal to this process
	while (1)
		sleep(1);
	return 0;
}
$ gcc -o signal1 signal1.c -Wall
$ ./signal1 
My pid is 21231

(āđƒāļŦāđ‰āļāļ” Ctrl+C āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰āļāļąāļšāđ‚āļ›āļĢāđāļāļĢāļĄ)

^C received SIGINT
^C received SIGINT
^C received SIGINT
^C received SIGINT
^C received SIGINT
^C received SIGINT

(āđƒāļŦāđ‰āļāļ” Ctrl+Z āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰āļāļąāļšāđ‚āļ›āļĢāđāļāļĢāļĄ)
^Z
[1]+  Stopped                 ./signal1

āļŦāļ™āđ‰āļēāļ•āđˆāļēāļ‡ Terminal 1 āđƒāļŦāđ‰āļ—āļģāļāļēāļĢ compile āđāļĨāļ°āļĢāļąāļ™āđ‚āļ›āļĢāđāļāļĢāļĄ signal1āļˆāļ°āļŠāļąāļ‡āđ€āļāļ•āđ€āļŦāđ‡āļ™āļ§āđˆāļēāđ‚āļ›āļĢāđāļāļĢāļĄāļˆāļ°āđāļŠāļ”āļ‡ Process ID (PID) āļ‚āļ­āļ‡āļ•āļąāļ§āđ€āļ­āļ‡ āđ€āļžāļ·āđˆāļ­āđƒāļŦāđ‰āđ‚āļ›āļĢāđ€āļ‹āļŠāļ­āļ·āđˆāļ™ āđ† āļŠāļēāļĄāļēāļĢāļ–āļŠāļ·āđˆāļ­āļŠāļēāļĢāđ„āļ”āđ‰

$ gcc -o signal1 signal1.c -Wall
$ ./signal1 
My pid is 21231 

āđƒāļŦāđ‰āđ€āļ›āļīāļ” terminal āđƒāļŦāļĄāđˆāļ­āļĩāļāļŦāļ™āđ‰āļēāļ•āđˆāļēāļ‡ (Terminal 2) āđāļĨāđ‰āļ§āđƒāļŦāđ‰āļžāļīāļĄāļžāđŒāļ„āļģāļŠāļąāđˆāļ‡ kill āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“ SIGINT āđ„āļ›āļĒāļąāļ‡ Process ID āļŦāļĄāļēāļĒāđ€āļĨāļ‚ 21231 āļ‹āļķāđˆāļ‡āļāđ‡āļ„āļ·āļ­āđ‚āļ›āļĢāđāļāļĢāļĄ signal1 āļ™āļąāđˆāļ™āđ€āļ­āļ‡ āļ”āļąāļ‡āđāļŠāļ”āļ‡āļ‚āđ‰āļēāļ‡āļĨāđˆāļēāļ‡

$ kill -s SIGINT 21231

āļˆāļ°āļŠāļąāļ‡āđ€āļāļ•āđ€āļŦāđ‡āļ™āļ‚āđ‰āļ­āļ„āļ§āļēāļĄāļ›āļĢāļēāļāļāļ‚āđ‰āļēāļ‡āļĨāđˆāļēāļ‡āđƒāļ™āļŦāļ™āđ‰āļēāļ•āđˆāļēāļ‡ Terminal 1 āļ”āļąāļ‡āļ™āļĩāđ‰

$ gcc -o signal1 signal1.c -Wall
$ ./signal1 
My pid is 21231
received SIGINT    <--------- āđāļŠāļ”āļ‡āļ‚āđ‰āļ­āļ„āļ§āļēāļĄāđ€āļĄāļ·āđˆāļ­āļ•āļĢāļ§āļˆāļˆāļąāļšāļŠāļąāļāļāļēāļ“ SIGINT āļˆāļēāļ Terminal 2

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 2

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļĨāļđāļāļˆāļ°āļ§āļ™āļĢāļ­āļĢāļąāļš signal āļ—āļĩāđˆāļˆāļ°āļ–āļđāļāļŠāđˆāļ‡āļĄāļēāļˆāļēāļāļœāļđāđ‰āđƒāļŠāđ‰āđ€āļŠāđˆāļ™ Ctrl+C āđ€āļ›āđ‡āļ™āļ•āđ‰āļ™ āđ‚āļ”āļĒāđ‚āļ›āļĢāđ€āļ‹āļŠāđāļĄāđˆāļˆāļ°āļĢāļ­āđ‚āļ›āļĢāđ€āļ‹āļŠāļĨāļđāļāļˆāļ™āļāļ§āđˆāļēāļˆāļ°āļ—āļģāļ‡āļēāļ™āļŠāļīāđ‰āļ™āļŠāļļāļ”

// signal2.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>

void HandlerChild() {
	printf("Sigint received by child \n");
}

void HandlerParent() {
	printf("Sigint received by Parent \n");
	signal(SIGINT, HandlerParent);
}

int n, statusp;

int main(void) {
// signal(SIGINT,HandlerParent);
	n = fork();
	if (n == 0) {
		printf("Child ID %d\n", getpid());
		signal(SIGINT, HandlerChild);
		for (;;) {
		};
	} else {
		printf("Parent ID %d \n", getpid());
// signal(SIGINT,HandlerParent);
		wait(&statusp);
// kill(n,SIGKILL);
		exit(0);
	}
	return 0;
}
$ gcc -o signal2 signal2.c -Wall 
$ ./signal2
Parent ID 4564 
Child ID 4565
^CSigint received by child 

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 3

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļāļēāļĢāđƒāļŠāđ‰āļŸāļąāļ‡āļāđŒāļŠāļąāļ™ alarm(5) āđ€āļžāļ·āđˆāļ­āļŠāļĢāđ‰āļēāļ‡āļŠāļąāļāļāļēāļ“āļ‚āļķāđ‰āļ™āļ—āļļāļāđ† 5 āļ§āļīāļ™āļēāļ—āļĩ

// signal3.c
#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int r, count = 0, n;

void HL_AlarmSig(int al) {
	printf(" I am active every 5 sec ");

	signal(SIGALRM, HL_AlarmSig);
	r = alarm(5);
	count++;
	printf(" .... Now the time is %d sec \n", count * 5);
}

void HL_AllSig(int s) {
	printf(" Oh ! I just received signal number %d \n", s);
	signal(s, HL_AllSig);
}

int main(void) {
	for (n = 1; n <= 31; n++) {
		signal(n, HL_AllSig);
	}
	signal(SIGALRM, HL_AlarmSig);
	r = alarm(5);
	while (count < 12) {
	};
	printf(" Program Terminate !! ");
	return 0;
}
$ gcc -o signal3 signal3.c -Wall 

$ ./signal3
^C Oh ! I just received signal number 2 
^C Oh ! I just received signal number 2 
^C Oh ! I just received signal number 2 
 I am active every 5 sec  .... Now the time is 5 sec 
^Z Oh ! I just received signal number 20 
^\ Oh ! I just received signal number 3 
 I am active every 5 sec  .... Now the time is 10 sec 
 I am active every 5 sec  .... Now the time is 15 sec 
^C Oh ! I just received signal number 2 
^C Oh ! I just received signal number 2 
^C Oh ! I just received signal number 2 
^Z Oh ! I just received signal number 20 
^Z Oh ! I just received signal number 20 
 I am active every 5 sec  .... Now the time is 20 sec 
 I am active every 5 sec  .... Now the time is 25 sec 
 I am active every 5 sec  .... Now the time is 30 sec 


 I am active every 5 sec  .... Now the time is 35 sec 
 I am active every 5 sec  .... Now the time is 40 sec 
 I am active every 5 sec  .... Now the time is 45 sec 
 I am active every 5 sec  .... Now the time is 50 sec 
 I am active every 5 sec  .... Now the time is 55 sec 
 I am active every 5 sec  .... Now the time is 60 sec 

āļˆāļēāļāļœāļĨāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄāļ‚āđ‰āļēāļ‡āļ•āđ‰āļ™āđ€āļĄāļ·āđˆāļ­āļĄāļĩāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡āļ„āļģāļŠāļąāđˆāļ‡ alarm(5) āļ—āļĩāđˆāļĄāļĩāļāļēāļĢāļŠāļĢāđ‰āļēāļ‡āļŠāļąāļāļāļēāļ“āļ‚āļķāđ‰āļ™āļ—āļļāļāđ† 5 āļ§āļīāļ™āļēāļ—āļĩ āđāļĨāđ‰āļ§āļ—āļģāđƒāļŦāđ‰āļĄāļĩāļāļēāļĢāđ€āļĢāļĩāļĒāļāļŸāļąāļ‡āļāđŒāļŠāļąāļ™ HL_AlarmSig() āđ€āļžāļ·āđˆāļ­āđāļŠāļ”āļ‡āļ‚āđ‰āļ­āļ„āļ§āļēāļĄāļ™āļąāļšāđ€āļ§āļĨāļē āđāļĨāđ‰āļ§āđ€āļžāļīāđˆāļĄāļ„āđˆāļēāļ•āļąāļ§āđāļ›āļĢ count āļ‚āļķāđ‰āļ™āđ„āļ›āđ€āļĢāļ·āđˆāļ­āļĒāđ† āļˆāļ™āļāļĢāļ°āļ—āļąāđˆāļ‡āđ€āļĄāļ·āđˆāļ­āļ„āđˆāļēāđƒāļ™āļ•āļąāļ§āđāļ›āļĢ count āđ€āļžāļīāđˆāļĄāļ‚āļķāđ‰āļ™āļˆāļ™āđ€āļ—āđˆāļēāļāļąāļšāļŦāļĢāļ·āļ­āļĄāļēāļāļāļ§āđˆāļē 12 āđ‚āļ›āļĢāđ€āļ‹āļŠāđāļĄāđˆāļāđ‡āļˆāļ°āļŠāļīāđ‰āļ™āļŠāļļāļ”āļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡āļ•āļąāļ§āđ€āļ­āļ‡ āļ”āļąāļ‡āļ™āļąāđ‰āļ™āđ€āļĄāļ·āđˆāļ­āļĢāļ§āļĄāđ€āļ§āļĨāļēāļ—āļĩāđˆāļ™āļąāļšāđāļĨāđ‰āļ§āđ€āļ—āđˆāļēāļāļąāļš 60 āļ§āļīāļ™āļēāļ—āļĩ (12 x 5) āļ™āļąāđˆāļ™āđ€āļ­āļ‡

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 4

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ‚āļ›āļĢāđāļāļĢāļĄāļ•āļĢāļ§āļˆāļŠāļ­āļšāļŠāļąāļāļāļēāļ“āļ•āļēāļĄāļ—āļĩāđˆāļāļģāļŦāļ™āļ”āđ€āļžāļ·āđˆāļ­āđ€āļĢāļĩāļĒāļāđ„āļ›āļĒāļąāļ‡āļŸāļąāļ‡āļāđŒāļŠāļąāļ™āļ—āļĩāđˆāļāļģāļŦāļ™āļ”āđ„āļ§āđ‰

// signal4.c
#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int r, n;

void HL_AlarmSig(int al) {
	printf(" Every 5 sec I have to tell you this PID \n");
	printf(" ....... THIS PROCESS ID = %d ....... \n", getpid());
	signal(SIGALRM, HL_AlarmSig);
	r = alarm(5);

}
void Nothing(int s) {
	signal(s, Nothing);
}

void InfiniteLoop(int s) {
	printf(" No ! I don't care signal number %d  \n", s);
	printf("If you want to stop this process send signal number 9 ONLY!!!\n");

	signal(s, InfiniteLoop);
	for (;;) {
		printf("Loop\n");
	}; /* infinite loop */

}

int main(void) {

	for (n = 1; n <= 31; n++) {
		signal(n, Nothing);
	}
	signal(SIGINT, InfiniteLoop);
	signal(SIGALRM, HL_AlarmSig);
	printf(" If you want to go into the infinite loop \n");
	printf("  .......press  ^C within 5 sec...... \n ");
	r = alarm(5);
	for (;;) {
	};
	printf(" Program Terminate !! \n");
	return 0;
}
$ gcc -o signal4 signal4.c -Wall
$ ./signal4 
If you want to go into the infinite loop
  .......press  ^C within 5 sec......
  Every 5 sec I have to tell you this PID
 ....... THIS PROCESS ID = 21538 .......
 Every 5 sec I have to tell you this PID
 ....... THIS PROCESS ID = 21538 .......

(āļ–āđ‰āļēāļāļ” Ctrl+C āđ‚āļ›āļĢāđāļāļĢāļĄāļˆāļ°āđ€āļ‚āđ‰āļēāļĨāļđāļ›āļ­āļ™āļąāļ™āļ•āđŒ)

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 5

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ‚āļ›āļĢāđāļāļĢāļĄ

// signal5.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>

int n, status;

void HL_Child(int s) {
	printf("**Child**I received signal No. %d .. you can't kill me \n", s);
	signal(s, HL_Child);
}

void HL_Parent(int s) {
	printf("***Parent*** I received signal number %d \n", s);
	signal(s, HL_Parent);
}
void HL_Parent14(int s) {
	printf("***Parent*** I received signal No. %d == Alarm Signal \n", s);
	signal(s, HL_Parent14);

}

void HL_Child14(int s) {
	printf("***Child*** I received signal No %d == Alarm Signal \n", s);
	signal(s, HL_Child14);
}
void HL_Child3(int s) {
	printf("***Child*** I received signal No %d  .. I will exit \n", s);
	exit(5);
}

int main(void) {
	int i;
	for (i = 1; i <= 31; i++)
		signal(i, HL_Parent);
	n = fork();
	if (n == 0) /* Child Process */
	{
		for (i = 1; i <= 31; i++)
			signal(i, HL_Child);
		signal(SIGALRM, HL_Child14);
		signal(3, HL_Child3);
		alarm(2);
		printf("--c--  Child ID  = %d  \n", getpid());
		printf("--c--  Child Process goes into the infinite loop \n");
		printf("--c--  Signal number 3 (^\\) can kill me \n");
		for (;;) {
		};
	} else /* Parent Process */
	{
		printf("--p--  Parent ID  = %d  \n", getpid());
		signal(SIGALRM, HL_Parent14);
		/* alarm(2);  */
		printf("--p--  I am waiting for child exit or any signal \n");
		wait(&status);
		printf("--p--  Wait completed !!  and I am waiting again ...\n");
		wait(&status);
		printf("--p--  Wait completed !! ...exit status = %d\n", status >> 8);
		printf("--p-- I am pausing for check signal from child exit ... \n");
		pause();
		wait(&status);
		printf("--p-- Wait completed !! ...exit status = %d \n", status >> 8);
		printf("--p-- I will execute newprog now !! \n");
		for (i = 1; i <= 31; i++)
			signal(i, SIG_IGN);
		signal(3, SIG_DFL);
		signal(2, HL_Parent);
		i = execl("newprog", "newprog", 0);
		printf("--p-- Parent Process terminated !!\n");
		exit(0);

	}
	return 0;
}
$ gcc -o signal5 signal5.c -Wall
$ ./signal5 
--p--  Parent ID  = 22119
--p--  I am waiting for child exit or any signal
--c--  Child ID  = 22120
--c--  Child Process goes into the infinite loop
--c--  Signal number 3 (^\) can kill me

(āļāļ” Ctrl+C āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰ child process)
^C***Parent*** I received signal number 2
**Child**I received signal No. 2 .. you can't kill me

(āļāļ” Ctrl+C āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰ child process)
^C***Parent*** I received signal number 2
**Child**I received signal No. 2 .. you can't kill me
***Child*** I received signal No 14 == Alarm Signal

(āļāļ” Ctrl+Z āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰ child process)
^Z**Child**I received signal No. 18 .. you can't kill me
***Parent*** I received signal number 18

(āļ–āđ‰āļēāļāļ” Ctrl+\ āđ€āļžāļ·āđˆāļ­āļŠāđˆāļ‡āļŠāļąāļāļāļēāļ“āđƒāļŦāđ‰ child process āđ€āļžāļ·āđˆāļ­āđ€āļĢāļĩāļĒāļāļŸāļąāļ‡āļāđŒāļŠāļąāļ™ HL_Child3() )
^\***Parent*** I received signal number 3
***Child*** I received signal No 3  .. I will exit
***Parent*** I received signal number 20
--p--  Wait completed !!  and I am waiting again ...
--p--  Wait completed !! ...exit status = 5
--p-- I am pausing for check signal from child exit ...

(āļāļ” Ctrl+C āđ€āļžāļ·āđˆāļ­āļŠāļąāđˆāļ‡āļŦāļĒāļļāļ”āđ‚āļ›āļĢāđāļāļĢāļĄ)
^C***Parent*** I received signal number 2
--p-- Wait completed !! ...exit status = 5
--p-- I will execute newprog now !!
--p-- Parent Process terminated !!

āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āļ—āļĩāđˆ 6

āđāļŠāļ”āļ‡āļ•āļąāļ§āļ­āļĒāđˆāļēāļ‡āđ‚āļ›āļĢāđāļāļĢāļĄāļ—āļĩāđˆāđƒāļŠāđ‰āļŠāļģāļŦāļĢāļąāļšāđāļāđ‰āļ›āļąāļāļŦāļēāļāļēāļĢāļˆāļąāļ”āļāļēāļĢāļ„āļīāļ§āļ‚āļ­āļ‡āļāļēāļĢāļŠāļīāđ‰āļ™āļŠāļļāļ”āļ‚āļ­āļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļĨāļđāļāļ—āļĩāđˆāđāļ•āļāļ•āđˆāļēāļ‡āļāļĢāļ“āļĩāļāļąāļ™ (exit statues) āļ‹āļķāđˆāļ‡āđ€āļĄāļ·āđˆāļ­āđ„āļŦāļĢāđˆāļāđ‡āļ•āļēāļĄāļ—āļĩāđˆāļŠāļ–āļēāļ™āļ°āļ‚āļ­āļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāļĨāļđāļāđ€āļ›āļĨāļĩāđˆāļĒāļ™āđāļ›āļĨāļ‡āđ‚āļ›āļĢāđ€āļ‹āļŠāđāļĄāđˆāļāđ‡āļˆāļ°āđ„āļ”āđ‰āļĢāļąāļšāļŠāļąāļāļāļēāļ“ SIGCHLD

/*
 *  signal6.c
 *  
 *  The parent process pulls a child exit status whenever the OS notifies
 *  a child status change.
 *
 *  Created by Mij <mij@bitchx.it> on 04/01/05.
 *  Original source file available at http://mij.oltrelinux.com/devel/unixprg/
 *
 */

/* for printf() and fgetc() */
#include <stdio.h>
/* for fork() */
#include <sys/types.h>
#include <unistd.h>
/* for srandom() and random() */
#include <stdlib.h>
/* for time() [seeding srandom()] */
#include <time.h>
/* for waitpid() */
#include <sys/wait.h>
/* for signal(), kill() and raise() */
#include <signal.h>

/* how many childs to raise */
#define NUM_PROCS   5

/* handler prototype for SIGCHLD */
void child_handler(int);

int main(int argc, char *argv[]) {
	int i, exit_status;

	/* execute child_handler() when receiving a signal of type SIGCHLD */
	signal(SIGCHLD, &child_handler);

	/* initialize the random num generator */
	srandom(time(NULL));

	printf("Try to issue a \'ps\' while the process is running...\n");

	/* produce NUM_PROCS childs */
	for (i = 0; i < NUM_PROCS; i++) {
		if (!fork()) {
			/* child */

			/* choosing a random exit status between 0 and 99 */
			exit_status = (int) (random() % 100);
			printf(" -> New child %d, will exit with %d.\n", (int) getpid(),
					exit_status);

			/* try to skip signals overlapping */
			sleep((unsigned int) (random() % 3));

			/* choosing a value to exit between 0 and 99 */
			exit(exit_status);
		}

		/* father */
		sleep((unsigned int) (random() % 2));
	}

	/* checkpoint */
	printf("parent: done with fork()ing.\n");

	/* why this is not equivalent to sleep(20) here? */
	for (i = 0; i < 10; i++) {
		sleep(1);
	}
	/* all the child processes should be done now */
	printf("I did not purge all the childs. Timeout; exiting.\n");

	/* terminate myself => exit */
	kill(getpid(), 15);

	/* this won't be actually executed */
	return 0;
}

/* handler definition for SIGCHLD */
void child_handler(int sig_type) {
	int child_status;
	pid_t child;
	static int call_num = 0;

	/* getting the child's exit status */
	child = waitpid(0, &child_status, 0);

	printf("<-  Child %d exited with status %d.\n", child,
			WEXITSTATUS(child_status));

	/* did we get all the childs? */
	if (++call_num >= NUM_PROCS) {
		printf("I got all the childs this time. Going to exit.\n");
		exit(0);
	}

	return;
}
$ gcc -o signal6 signal6.c -Wall

$ ./signal6 
Try to issue a 'ps' while the process is running...
 -> New child 12274, will exit with 68.
 -> New child 12275, will exit with 57.
 -> New child 12276, will exit with 96.
parent: done with fork()ing.
 -> New child 12277, will exit with 18.
 -> New child 12278, will exit with 72.
<-  Child 12275 exited with status 57.
<-  Child 12274 exited with status 68.
<-  Child 12277 exited with status 18.
<-  Child 12276 exited with status 96.
<-  Child 12278 exited with status 72.
I got all the childs this time. Going to exit.
PreviousIPC AnatomyNextPipe Programming

Last updated 1 year ago

Was this helpful?

ðŸ–Ĩïļ
āļāļĨāđ„āļāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡ signalling