So it's a QT question. That constrains the space enough that I can provide an answer for the most reasonable case.
A good portable program probably does not monitor arbitrary processes but only its own; and for that everything is well in hand. Child processes are spawned using the QProcess
class, and it provides of itself what you need in the form of the stateChanged
signal. You don't ever ask if the process ID is good; you get told when it's no longer good.
If you insist on checking if the PID is good; you're in luck. If /proc/self
exists but /proc/${pid}
doesn't than the PID isn't good anymore. This works about as well as EnumProcesses
on windows. You can get the process name from /proc/${pid}/exe
(it's a symbolic link, so call readlink()
on it). If /proc/self
doesn't exist, you probably can't enum processes because the system is in a degenerate state.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…