一般來說,查看service狀態會執行命令
systemctl status rfidgw
然後就會看到該service狀態
//-----------start----------- ● rfidgw.service - rfidgw service description Loaded: loaded (/lib/systemd/system/rfidgw.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-05-24 15:12:17 CST; 1min 51s ago Process: 6823 ExecStartPre=/usr/bin/touch /var/log/heartgw.log (code=exited, status=0/SUCCESS) Main PID: 6824 (rfidgw_spi1) Tasks: 7 (limit: 2062) CGroup: /system.slice/rfidgw.service └─6824 /home gw rfidgw rfidgw_spi1 May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.079: DMGW_UUID:1d0c0fcc-f805-4e67-92d7-a72e2b7ca724 May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.112: Repy_Handler:: 21081 May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.112: SOC_SERIAL:000000004B1B363F May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.113: HOSTNAME:DMGW-43A May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.113: ==[ RFIDGW_RESTART_REASON:null ]== May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.152: RFID_A7127_ProcTH May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.180: -------------------------------------------------------------- May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.180: [[]]===Use Socket Client to get RFID Tag====]] May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.181: [[]]===Use Socket Client to get RFID Tag====]] //------------end------------
上述結果中的Main PID
則是Service執行PID,我們用參數的方式直接取得Main PID
屬性的值
systemctl show --property MainPID --value rfidgw
執行後會返回該屬性的值
6824
以上就是取得該service的PID,利用ps
指定返查
ps -f --pid 6824
會得到結果如下
UID PID PPID C STIME TTY TIME CMD root 6824 1 18 15:12 ? 00:00:09 /home gw rfidgw rfidgw_spi1
The post 20210525-systemctl 取得 service pid appeared first on 可丁丹尼 @ 一路往前走2.0.