Is there any way to tell if a process has terminated?

I am looking for a way for my process to determine whether another process
has terminated or not. My process kills the other process and waits for the
process to be terminated. Is there a library function I could call to find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

kill(pid, 0)

Rex Lam wrote:

I am looking for a way for my process to determine whether another process
has terminated or not. My process kills the other process and waits for the
process to be terminated. Is there a library function I could call to find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

What is the exact process for launching and terminating the process?

If you are doing the standard fork() and exec() or spawn() you could just
waitpid() until the process has terminated.

You could send a well known pulse to the waiting process to indicated that
the specific process has terminated.

You could also register the process and perform a name_open()/name_close()
to determine if it is still registered.

Other than that, I would need more info.

Hope this helps.

“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9pd83u$5pk$1@inn.qnx.com

I am looking for a way for my process to determine whether another process
has terminated or not. My process kills the other process and waits for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

I tried that but it did not work. My process is a resource manager (uses
ChannelCreate, dispatch_create, resmgr_attach, message_attach,
message_connect). I have tried in a different process that is not a
resource manager but uses name_attach and kill (pid, 0) works. However, in
my process, when the target process is terminated (using kill (pid,
SIGTERM)), the pid is still valid. I checked “/proc” after terminating the
process and the pid stays until my process is terminated. Is there a flag I
could set so that the pid is removed from “/proc” when the target process is
terminated? If not, is there another function to call that could check
whether a process is terminated or not?

Thanks.
Rex


“Dean Douthat” <ddouthat@faac.com> wrote in message
news:3BBA2A24.80E40300@faac.com

kill(pid, 0)

Rex Lam wrote:

I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9pda55$71u$1@inn.qnx.com

I tried that but it did not work. My process is a resource manager (uses
ChannelCreate, dispatch_create, resmgr_attach, message_attach,
message_connect). I have tried in a different process that is not a
resource manager but uses name_attach and kill (pid, 0) works. However,
in
my process, when the target process is terminated (using kill (pid,
SIGTERM)), the pid is still valid. I checked “/proc” after terminating
the
process and the pid stays until my process is terminated. Is there a flag
I
could set so that the pid is removed from “/proc” when the target process
is
terminated? If not, is there another function to call that could check
whether a process is terminated or not?

Is this a process that you’ve started (a child), if so look at wait()

Thanks.
Rex


“Dean Douthat” <> ddouthat@faac.com> > wrote in message
news:> 3BBA2A24.80E40300@faac.com> …
kill(pid, 0)

Rex Lam wrote:

I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits
for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

Thanks for the suggestion, but I cannot make the assumption that it is a
child process. The target process could be started by another process. Any
other suggestions?

Rex


“Mario Charest” <mcharest@voidzinformatic.com> wrote in message
news:9pdajh$73m$1@inn.qnx.com

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9pda55$71u$> 1@inn.qnx.com> …
I tried that but it did not work. My process is a resource manager
(uses
ChannelCreate, dispatch_create, resmgr_attach, message_attach,
message_connect). I have tried in a different process that is not a
resource manager but uses name_attach and kill (pid, 0) works. However,
in
my process, when the target process is terminated (using kill (pid,
SIGTERM)), the pid is still valid. I checked “/proc” after terminating
the
process and the pid stays until my process is terminated. Is there a
flag
I
could set so that the pid is removed from “/proc” when the target
process
is
terminated? If not, is there another function to call that could check
whether a process is terminated or not?


Is this a process that you’ve started (a child), if so look at wait()

Thanks.
Rex


“Dean Douthat” <> ddouthat@faac.com> > wrote in message
news:> 3BBA2A24.80E40300@faac.com> …
kill(pid, 0)

Rex Lam wrote:

I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits
for
the
process to be terminated. Is there a library function I could call
to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

\

Thank you for your suggestion. I think name_open/name_close is the most
suitable for my case. However, I have trouble finding the correct name to
open. My process acts like a system monitor. It terminates processes when
an error is detected. It gets a list of valid pids from /proc. However, it
has no knowledge of the processes’ names. Any suggestions?

Rex

“Kevin Hykin” <kevin.hykin@bepco.com> wrote in message
news:9pd9ve$6pl$1@inn.qnx.com

What is the exact process for launching and terminating the process?

If you are doing the standard fork() and exec() or spawn() you could just
waitpid() until the process has terminated.

You could send a well known pulse to the waiting process to indicated that
the specific process has terminated.

You could also register the process and perform a name_open()/name_close()
to determine if it is still registered.

Other than that, I would need more info.

Hope this helps.

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9pd83u$5pk$> 1@inn.qnx.com> …
I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex
\

Slightly off-topic, but has anyone else noticed that, with respect to

kill(pid, 0)

If the pid specified is a child that is a “zombie” (i.e. it has died but
hasn’t been wait()'ed for yet),
then

  • Under QNX4, this will fail (return -1 and ESRCH)
  • Under QNX6, this will succeed.

Is the “correct” behaviour specified by POSIX?

I find it safer and more portable between QNX4 and QNX6 to use

waitpid( pid, &status, WNOHANG)

but of course this has side effects that are different to kill(pid, 0).

Rob Rutherford

“Dean Douthat” <ddouthat@faac.com> wrote in message
news:3BBA2A24.80E40300@faac.com

kill(pid, 0)

Rex Lam wrote:

I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex

Robert Rutherford <ruzz@ruzz.com> wrote:

Slightly off-topic, but has anyone else noticed that, with respect to

kill(pid, 0)

If the pid specified is a child that is a “zombie” (i.e. it has died but
hasn’t been wait()'ed for yet),
then

  • Under QNX4, this will fail (return -1 and ESRCH)
  • Under QNX6, this will succeed.

Is the “correct” behaviour specified by POSIX?

QNX 6 has it right. The latest POSIX standard states that existing
implementations did it both ways, but that the latter is the way they
want it to be.

Note that if you spawn with the P_NOWAITO flag (at the bottom the
SPAWN_NOZOMBIE flag is set in the spawn attributes structure), then the
process will not go into the zombie state and the kill(pid, 0) will work
as expected - though you won’t be able to do a waitpid on the process
anymore. Alternatively - and POSIX conformant, use sigignore(SIGCHLD) to
ignore the SIGCHLD signal. That’ll cause children bypass the zombie
state as well.


Brian Stecher (bstecher@qnx.com) QNX Software Systems, Ltd.
phone: +1 (613) 591-0931 (voice) 175 Terence Matthews Cr.
+1 (613) 591-3579 (fax) Kanata, Ontario, Canada K2M 1W8

It sounds like the only option is to have each process report their name and
pid to the System Monitor so it can handle them appropriately.


“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9pdf1c$9h3$1@inn.qnx.com…> Thank you for your suggestion. I think
name_open/name_close is the most

suitable for my case. However, I have trouble finding the correct name to
open. My process acts like a system monitor. It terminates processes
when
an error is detected. It gets a list of valid pids from /proc. However,
it
has no knowledge of the processes’ names. Any suggestions?

Rex

“Kevin Hykin” <> kevin.hykin@bepco.com> > wrote in message
news:9pd9ve$6pl$> 1@inn.qnx.com> …
What is the exact process for launching and terminating the process?

If you are doing the standard fork() and exec() or spawn() you could
just
waitpid() until the process has terminated.

You could send a well known pulse to the waiting process to indicated
that
the specific process has terminated.

You could also register the process and perform a
name_open()/name_close()
to determine if it is still registered.

Other than that, I would need more info.

Hope this helps.

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9pd83u$5pk$> 1@inn.qnx.com> …
I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits
for
the
process to be terminated. Is there a library function I could call to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex


\

I’ll see what I can do. Thanks for your help.

“Kevin Hykin” <kevin.hykin@bepco.com> wrote in message
news:9pfu28$o0k$1@inn.qnx.com

It sounds like the only option is to have each process report their name
and
pid to the System Monitor so it can handle them appropriately.


“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9pdf1c$9h3$> 1@inn.qnx.com> …> Thank you for your suggestion. I think
name_open/name_close is the most
suitable for my case. However, I have trouble finding the correct name
to
open. My process acts like a system monitor. It terminates processes
when
an error is detected. It gets a list of valid pids from /proc.
However,
it
has no knowledge of the processes’ names. Any suggestions?

Rex

“Kevin Hykin” <> kevin.hykin@bepco.com> > wrote in message
news:9pd9ve$6pl$> 1@inn.qnx.com> …
What is the exact process for launching and terminating the process?

If you are doing the standard fork() and exec() or spawn() you could
just
waitpid() until the process has terminated.

You could send a well known pulse to the waiting process to indicated
that
the specific process has terminated.

You could also register the process and perform a
name_open()/name_close()
to determine if it is still registered.

Other than that, I would need more info.

Hope this helps.

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9pd83u$5pk$> 1@inn.qnx.com> …
I am looking for a way for my process to determine whether another
process
has terminated or not. My process kills the other process and waits
for
the
process to be terminated. Is there a library function I could call
to
find
out this information?

Any help would be greatly appreciated.

Thanks.
Rex




\