[Qt-interest] Is there anyways to check if a Process is Alive ?

Srdjan Todorovic todorovic.s at googlemail.com
Fri Mar 26 11:29:55 CET 2010


On 26/03/2010, Sean Harmer <sean.harmer at maps-technology.com> wrote:

> Longer option is to look at the code of ps and see what it does.

Problem is, the OP doesn't want to use /proc for compatibility reasons..

And a sample run of 'ps' on my Linux box:

stat64("/proc/9961", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
open("/proc/9961/stat", O_RDONLY)       = 6
read(6, "9961 (kwin) S 9946 9946 9946 0 -"..., 1023) = 194
close(6)

Which repeats for each process... So it seems that 'ps' just reads
files in /proc and then pretty-prints the information to screen.

Although, perhaps looking at the source of 'ps' on *BSD might help
come up with a design where there are platform dependent classes to
access process list and then have some method of switching these.
Perhaps a Strategy Pattern that is selected using the Q_OS_FREEBSD,
Q_OS_LINUX, Q_OS_NETBSD and Q_OS_OPENBSD macros from QtGlobal ?

Srdjan



More information about the Qt-interest-old mailing list