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
  • คำสั่งสำหรับการบริหารจัดการโปรเซส
  • jobs, ps

Was this helpful?

  1. Operation Systems
  2. Linux OS Dev. Engineer
  3. Process Management

Basic Process Mgmt. Commands

คำสั่งสำหรับการบริหารจัดการโปรเซส

ในการบริหารจัดการโปรเซสที่เกิดขึ้นในระหว่างเครื่องทำงานอยู่ จะเป็นหน้าที่หลักของระบบปฏิบัติการลีนุกซ์ ที่จะต้องจัดลำดับการร้องขอจากแต่ละโปรเซสเพื่อเข้าใช้ทรัพยากรของระบบ ดังนั้นโปรเซสทุกตัวจะต้องมีหมายเลขประจำของตัวเอง ซึ่งจะถูกกำหนดมาให้จากระบบปฏิบัติการเอง เรียกว่า PID (process id) แต่อย่างไรก็ตามผู้ใช้หรือนักพัฒนาก็สามารถควบคุมและบริหารจัดการกับโปรเซสที่เกิดจากการเรียกด้วยตัวผู้ใช้เอง โดยสามารถบริหารจัดการแยกเป็น กลุ่มได้แก่

  • การติดตามดูสถานะของโปรเซสโดยรวมด้วยคำสั่ง jobs

  • เลือกดูเฉพาะโปรเซสที่ต้องการ และค่าต่างที่ต้องการ

  • การส่งสัญญาณ (signals) แบบต่างไปยังโปรเซส

jobs, ps

คำสั่งที่เกี่ยวกับการติดตามดูสถานะของโปรเซสโดยรวมนั้น หลักมีอยู่ 2 คำสั่งคือ jobs และ ps (process snapshot) โดยคำสั่ง jobs นั้นจะแสดงหมายเลขของงานที่ถูกเรียกขึ้นมาตามลำดับ และมีหมายเลขโปรเซส (PID) อยู่ด้วย นอกจากนั้นคำสั่งนี้จะบอกสถานะของโปรเซสทั้งหมดว่าเป็นอย่างไรบ้าง เช่น กำลังทำงาน (running) ถูกหยุดการทำงาน (stopped) ถูกสั่งให้สิ้นสุดการทำงาน (killed) เป็นต้น ดังตัวอย่างคำสั่งข้างล่าง

$ jobs -l
[1]  11958 Running                 ./hello &
[2]- 12458 Stopped                 emulator &  (wd: ~/aosp)
[3]+ 12794 Killed                  gcalctool

สำหรับคำสั่ง ps มีหน้าที่ในการแสดงรายละเอียดโปรเซส ตัวอย่างเช่น ถ้ารับรายการ PID มาจากคำสั่ง jobs ที่ระบุตัวเลือก -p (การลำดับ process group leader) ก็จะแสดงรายละเอียดของหมายเลขโปร เซสเหล่านั้น ดังตัวอย่างข้างล่าง

$ jobs -p
11958
12458
12818

ในกรณีที่ผู้ดูแลระบบต้องการทราบถึงสถานะโปรเซสทั้งหมดที่ทำงานอยู่ในระบบ ผู้ดูแลระบบจำเป็นต้องมีการเพิ่มตัวเลือก -ef ต่อท้ายคำสั่ง ps เพื่อแสดงผลโปรเซสทั้งหมดที่ทำงานอยู่ในระบบในขณะนั้น ดังตัวอย่างข้างล่าง

$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Aug19 ?        00:00:01 /sbin/init
root         2     0  0 Aug19 ?        00:00:00 [kthreadd]
root         3     2  0 Aug19 ?        00:00:01 [migration/0]
root         4     2  0 Aug19 ?        00:00:08 [ksoftirqd/0]
root         5     2  0 Aug19 ?        00:00:00 [watchdog/0]
root         6     2  0 Aug19 ?        00:00:01 [migration/1]
root         7     2  0 Aug19 ?        00:00:08 [ksoftirqd/1]
root         8     2  0 Aug19 ?        00:00:00 [watchdog/1]
root        10     2  0 Aug19 ?        00:00:01 [events/1]
root        11     2  0 Aug19 ?        00:00:00 [cpuset]
root        12     2  0 Aug19 ?        00:00:00 [khelper]
root        13     2  0 Aug19 ?        00:00:00 [netns]
root        14     2  0 Aug19 ?        00:00:00 [async/mgr]
root        18     2  0 Aug19 ?        00:00:00 [bdi-default]
root        19     2  0 Aug19 ?        00:00:00 [kintegrityd/0]
root        20     2  0 Aug19 ?        00:00:00 [kintegrityd/1]
root        21     2  0 Aug19 ?        00:00:01 [kblockd/0]
root       306     2  0 Aug19 ?        00:00:05 [jbd2/sda1-8]
root      1268     1  0 Aug19 tty3     00:00:00 /sbin/getty -8 38400 tty3
root      1272     1  0 Aug19 tty6     00:00:00 /sbin/getty -8 38400 tty6
root      1275     1  0 Aug19 ?        00:00:07 /usr/sbin/irqbalance
student  11825 11824  0 05:21 ?        00:00:00 gnome-pty-helper
student  11826 11824  0 05:21 pts/0    00:00:00 bash
student  11958 11826 99 05:22 pts/0    01:24:29 ./hello
student  12458 11826  5 05:42 pts/0    00:03:43 /home/student/android/sdk/tools/
student  12515     1  0 05:43 pts/0    00:00:00 adb fork-server server
student  12818 11826  0 06:26 pts/0    00:00:00 gcalctool
root     12856     2  0 06:32 ?        00:00:00 [flush-8:0]
student  12929 11826  0 06:47 pts/0    00:00:00 ps -ef

จากผลลัพธ์ที่ได้จะสามารถทราบได้ว่ามีโปรเซสไหนบ้างที่เกิดจากการเรียกของผู้ใช้คนใด (UID) มีหมายเลขโปรเซส อะไร (PID) และเกิดขึ้นจากการเรียกของโปรเซสใด (PPID) เป็นต้น รายละเอียดดังอธิบายในตารางต่อไปนี้

ตารางแสดงรายละเอียดของคำสั่ง ps

คอลัมน์
ความหมาย

UID

แสดง user เจ้าของโปรเซส

PID

แสดงหมายเลขโปรเซส (Process ID)

PPID

แสดงหมายเลขโปรเซสหลักที่ได้รับการสืบทอดมา (Parent Process ID)

C

แสดงการใช้งาน CPU

STIME

แสดงเวลาที่โปรเซสเริ่มต้น

TTY

แสดงรหัสเทอมินอลที่โปรเซสทำงานอยู่

TIME

เวลาโดยรวมที่เข้าไปใช้งาน CPU

CMD

ชื่อคำสั่งที่ใช้ในการสร้างโปรเซสขึ้นมา

เมื่อต้องการดูเฉพาะโปรเซสที่เกิดขึ้นจากการเรียกใช้ใน bash shell สามารถใช้ตัวเลือก เช่น -f (full), -j (jobs), -l (long), --forest, --sort ดังตัวอย่างการใช้งานข้างล่าง

$ ps
  PID TTY          TIME CMD
11826 pts/0    00:00:00 bash
11958 pts/0    01:19:16 hello
12458 pts/0    00:03:31 emulator64-x86
12515 pts/0    00:00:00 adb
12818 pts/0    00:00:00 gcalctool
12905 pts/0    00:00:00 ps


$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
student  11826 11824  0 05:21 pts/0    00:00:00 bash
student  11958 11826 99 05:22 pts/0    01:19:17 ./hello
student  12458 11826  5 05:42 pts/0    00:03:31 /home/student/android/sdk/tools/
student  12515     1  0 05:43 pts/0    00:00:00 adb fork-server server
student  12818 11826  0 06:26 pts/0    00:00:00 gcalctool
student  12906 11826  0 06:42 pts/0    00:00:00 ps -f


$ ps -j --forest
  PID  PGID   SID TTY          TIME CMD
11826 11826 11826 pts/0    00:00:00 bash
11958 11958 11826 pts/0    01:19:31  \_ hello
12458 12458 11826 pts/0    00:03:31  \_ emulator64-x86
12818 12818 11826 pts/0    00:00:00  \_ gcalctool
12908 12908 11826 pts/0    00:00:00  \_ ps
12515 12514 11826 pts/0    00:00:00 adb


$ ps -aj --sort sid,comm
  PID  PGID   SID TTY          TIME CMD
12515 12514 11826 pts/0    00:00:00 adb
12458 12458 11826 pts/0    00:04:26 emulator64-x86
12818 12818 11826 pts/0    00:00:00 gcalctool
11958 11958 11826 pts/0    01:42:27 hello
13020 13020 11826 pts/0    00:00:00 ps

การหยุดการทำงานของโปรเซส (Process Killing) ในระบบปฏิบัติการลีนุกซ์นั้นจะใช้หลักการส่งข้อความของระบบในระดับล่าง (low-level system message) ที่เรียกกันว่า สัญญาณ (Signal) โดยสัญญาณจะถูกส่งไปขัดจังหวะโปรเซส เพื่อบอกกับโปรเซสตามวัตถุประสงค์ของสัญญาณนั้น ซึ่งในระบบปฏิบัติิการลีนุกซ์จะมีชนิดของสัญญาณอยู่ทั้งสิ้น 64 ชนิด สามารถดูรายละเอียดได้จากการพิมพ์คำสั่ง kill -l ดังข้างล่างนี้

$ kill -l

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

ตัวอย่างสัญญาณที่สำคัญและใช้งานบ่อย ตัวอย่างเช่น

  • สัญญาณหมายเลข 1 (SIGHUP) คือ Hang Up Signal เป็นสัญญาณที่ถูกส่งออกไปในขณะที่ terminal ถูกปิดลงเพื่อทำให้โปรเซสที่ถูกเรียกภายใต้ terminal ถูกปิดลงตามด้วย

  • สัญญาณหมายเลข 3 (SIGQUIT) คือ Quit Signal เป็นสัญญาณที่ถูกส่งออก ในขณะที่ผู้ใช้งานได้มีการสั่งให้ โปรเซสนั้นปิดตัวลง

  • สัญญาณหมายเลข 6 (SIGABRT) คือ Abort Signal เป็นสัญญาณที่ถูกส่งออกมาจากโปรเซสที่ต้องการปิดตัวเองลง

  • สัญญาณหมายเลข 9 (SIGKILL) คือ Kill Signal ลักษณะชอง signal ประเภทนี้จะคล้ายกับการดึงสายไฟออกจากเครื่องคอมพิวเตอร์ กล่าวคือเป็นการสั่งให้โปรเซสปิดตัวลงทันทีไม่ว่าจะทำงานอะไรอยู่ก็ตาม

  • สัญญาณหมายเลข 18 (SIGCONT) คือ Continue Signal เป็นสัญญาณที่สั่งให้โปรเซสนั้นกลับมาทำงานปกติเช่นเดิม เช่นเดียวกันการสั่งให้โปรเซสกลับมาทำงานเบื้องหน้า (foreground)

  • สัญญาณหมายเลข 20 (SIGTSTP) คือ การส่ง Stop Signal ด้วย Keyboard (Ctrl+Z) เป็นสัญญาณที่สั่งให้โปรเซสนั้นถูกทำให้ไปทำงานเบื้องหลัง (background) เช่นเดียวกับการกดปุ่ม Ctrl+Z บนคีย์บอร์ด

ตัวอย่างการส่งสัญญาณผ่านคีย์บอร์ด

เป็นวิธีการหนึ่งของการส่งสัญญาณให้กับโปรเซส โดยเมื่อมีกดคำสั่งบนคีย์บอร์ดดังนี้

Ctrl-C

ส่งสัญญาณ INT (SIGINT) ไปยังโปรเซสที่ทำงานอยู่ยุติการทำงานทันที

Ctrl-Z

ส่งสัญญาณ TSTP (SIGTSTP) ไปยังโปรเซสที่ทำงานอยู่ให้หยุดชั่วคราว

Ctrl-\

ส่งสัญญาณ ABRT (SIGABRT) ไปยังโปรเซสที่ทำงานอยู่ให้ยุติการทำงานของโปรเซสนั้นทันที เหมือน Ctrl-C แต่เป็นคำสั่งที่ดีกว่าคือสามารถแก้ไขได้

$ jobs -l
[1]  11958 Running                 ./hello &
[2]- 12458 Running                 emulator &  (wd: ~/aosp)
[3]+ 12818 Running                 gcalctool &


$ kill -s SIGTSTP 12818
$ jobs -l
[1]  11958 Running                 ./hello &
[2]- 12458 Running                 emulator &  (wd: ~/aosp)
[3]+ 12818 Stopped                 gcalctool


$ kill -s SIGCONT 12818
$ jobs -l
[1]  11958 Running                 ./hello &
[2]- 12458 Running                 emulator &  (wd: ~/aosp)
[3]+ 12818 Running                 gcalctool &


$ kill -s SIGKILL 12818
$ jobs -l
[1]  11958 Running                 ./hello &
[2]- 12458 Running                 emulator &  (wd: ~/aosp)
[3]+ 12818 Killed                  gcalctool


$ kill -s SIGTERM 11958
$ jobs -l
[1]  11958 Terminated              ./hello
[2]- 12458 Running                 emulator &  (wd: ~/aosp)
PreviousProcess StateNextAdvance Process Mgmt. Commands

Last updated 1 year ago

Was this helpful?

🖥️