linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Running status of a process
@ 2007-03-21  8:13 Prasanta Sadhukhan
  2007-03-21  8:30 ` Steve Graegert
  2007-03-21  8:33 ` Prasanta Sadhukhan
  0 siblings, 2 replies; 4+ messages in thread
From: Prasanta Sadhukhan @ 2007-03-21  8:13 UTC (permalink / raw)
  To: linux-c-programming

Hi,

Can anyone point as to how can I obtain the information whether a 
non-child process is still running?

I tried waitpid(pid, &status, WNOHANG) but always receive return value 
as -1 with errno as ECHILD.
Since the processes I am waiting for is not the child of this process 
from where I am calling waitpid() (ie, they are independant processes), 
it might be a valid error but what is the other alternative?

Regards
Prasanta


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Running status of a process
  2007-03-21  8:13 Running status of a process Prasanta Sadhukhan
@ 2007-03-21  8:30 ` Steve Graegert
  2007-03-21  8:34   ` Prasanta Sadhukhan
  2007-03-21  8:33 ` Prasanta Sadhukhan
  1 sibling, 1 reply; 4+ messages in thread
From: Steve Graegert @ 2007-03-21  8:30 UTC (permalink / raw)
  To: Prasanta Sadhukhan; +Cc: linux-c-programming

Prasanta,

On 3/21/07, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> wrote:
> Hi,
>
> Can anyone point as to how can I obtain the information whether a
> non-child process is still running?

If you know the PID of the process you want to obtain the status of
use the kill(2) system call.  The second argument should be 0 (zero)
to prevent a signal from being sent to the process.  If the process
exists kill(2) returns zero, or -1 otherwise.

kill(2) can indicate various errors, but an error or EPERM usually is
an indicator that the process exists, while all others indicate that
it does not.

If you're writing for systems supporting the /proc filesystem,
checking for existence of /proc/{pid} is an alternative.

If you don't know the PID you're out of luck, unless you make use of
the /proc filesystem again, which is not portable per se.

	\Steve

--

Steve Grägert <steve@graegert.com>
Jabber    xmpp://graegerts@jabber.org
Internet  http://eth0.graegert.com, http://blog.graegert.com
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Running status of a process
  2007-03-21  8:13 Running status of a process Prasanta Sadhukhan
  2007-03-21  8:30 ` Steve Graegert
@ 2007-03-21  8:33 ` Prasanta Sadhukhan
  1 sibling, 0 replies; 4+ messages in thread
From: Prasanta Sadhukhan @ 2007-03-21  8:33 UTC (permalink / raw)
  To: Prasanta Sadhukhan; +Cc: linux-c-programming

Prasanta Sadhukhan wrote:

> Hi,
>
> Can anyone point as to how can I obtain the information whether a 
> non-child process is still running?
>
> I tried waitpid(pid, &status, WNOHANG) but always receive return value 
> as -1 with errno as ECHILD.
> Since the processes I am waiting for is not the child of this process 
> from where I am calling waitpid() (ie, they are independant 
> processes), it might be a valid error but what is the other alternative?
>
> Regards
> Prasanta

Got it...Should have called kill(pid, 0)
Thanks anyways

>
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Running status of a process
  2007-03-21  8:30 ` Steve Graegert
@ 2007-03-21  8:34   ` Prasanta Sadhukhan
  0 siblings, 0 replies; 4+ messages in thread
From: Prasanta Sadhukhan @ 2007-03-21  8:34 UTC (permalink / raw)
  To: Steve Graegert; +Cc: linux-c-programming

Steve Graegert wrote:

> Prasanta,
>
> On 3/21/07, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> wrote:
>
>> Hi,
>>
>> Can anyone point as to how can I obtain the information whether a
>> non-child process is still running?
>
>
> If you know the PID of the process you want to obtain the status of
> use the kill(2) system call.  The second argument should be 0 (zero)
> to prevent a signal from being sent to the process.  If the process
> exists kill(2) returns zero, or -1 otherwise.
>
> kill(2) can indicate various errors, but an error or EPERM usually is
> an indicator that the process exists, while all others indicate that
> it does not.
>
> If you're writing for systems supporting the /proc filesystem,
> checking for existence of /proc/{pid} is an alternative.
>
> If you don't know the PID you're out of luck, unless you make use of
> the /proc filesystem again, which is not portable per se.

thanks steve, found the solution.. I guess my mail crossed yours in the path

Prasanta

>
>     \Steve
>
> -- 
>
> Steve Grägert <steve@graegert.com>
> Jabber    xmpp://graegerts@jabber.org
> Internet  http://eth0.graegert.com, http://blog.graegert.co
> m



-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-21  8:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-21  8:13 Running status of a process Prasanta Sadhukhan
2007-03-21  8:30 ` Steve Graegert
2007-03-21  8:34   ` Prasanta Sadhukhan
2007-03-21  8:33 ` Prasanta Sadhukhan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).