子程序清理

2021-09-22 11:18:27 字數 956 閱讀 4796

一般我們在程式設計的時候,我們使用wait來獲取子程序的退出狀態,但是wait將會阻塞等到子程序結束。對於waitpid來說:

pid_t waitpid(pid_t pid, int *statloc, int options);

我們可以通過設定第3個引數options為wnohang來使waitpid為非阻塞,但這樣的話,我們就需要不斷的呼叫waitpid來探測子程序是否結束。

signal中有乙個sigchld,當乙個程序終止或停止時,將sigchld訊號傳送給其父程序。按照系統預設情況,這個訊號是被忽略的。如果父程序希望被告知其子程序的這種狀態的變化,則應該設定捕獲這個訊號。在訊號處理函式裡面,通常要呼叫一種wait來獲取子程序的id和其退出狀態。

#include 

<

sys/

types.h

>

#include

<

unistd.h

>

#include

<

stdio.h

>

#include

<

string

.h>

#include

<

sys/

wait.h

>

#include

<

signal.h

>

sig_atomic_t child_exit_state;

void

clean_child_process(

intsig_number)

intmain(

intargc,

char

**ar**)

intmain(

intargc,

char

**ar**)

else

return0;

}

Linux 如何清理殭屍程序

今天在維護伺服器的時候,發現有5個nova novncproxy的殭屍程序。定義 in unix system terminology,a process that has terminated,but whose parent has not yet waited for it,is called...

自動清理殭屍程序及STOP程序指令碼

bin bash echo 殭屍程序 check ps a o stat,ppid,pid,cmd grep e zz if n check then echo 發現殭屍程序 for pid in ps a o stat,ppid,pid,cmd grep e zz awk do kill 9 pi...

Linux 痕跡清理 隱藏程序

1.偷換系統二進位制檔案 ps top 等 防範 比對hash 系統完整性檢查工具,比如tripwrie aide等 2.修改hook呼叫函式 修改命令返回結果,原函式getdents 防範 sysdig 開源 檢測ld preload環境變數是否有異常,ld.so.preload檔案異常 時間,大...