开发者

expected duration between kill and the ability to reap with waitpid

开发者 https://www.devze.com 2023-03-22 00:36 出处:网络
I have a Linux app which must spawn a child process on request with one of the exec() functions. If the child process has not finished before it\'s time to spawn it again, the app must kill the prev

I have a Linux app which must spawn a child process on request with one of the exec() functions.

If the child process has not finished before it's time to spawn it again, the app must kill the previous instance before starting the new one. It does this with

kill(pid, SIGTERM);

I'开发者_JAVA百科m keeping the pid of the previous instance and using

waitpid(pid, &status, WNOHANG)

to reap the process.

It seems that sometimes there's an extremely long time window (possibly into the hundreds of milliseconds) between issuing the kill call and being able to reap the process with waitpid.

What could cause this? I thought that unless the child process set a signal hander (this one doesn't) then it would be killed virtually immediately. This is on a 200MHz ARM9 but still ... seems odd to me.


The process may catch SIGTERM in order to perform its own cleanup before shutting down.

Even if it doesn't, you don't know how long it'll take the OS to shut down the process.

Trying to rely on things like this is a fool's errand.

0

精彩评论

暂无评论...
验证码 换一张
取 消