www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - check for running process

reply Dsmith <Dsmith nomail.com> writes:
In the core.thread library, there is a method isRunning() which takes a thread.

To make code more portable, rather than use a system call or getenv(), how might
isRunning() be adapted to check if a program is running?
Ideally: isrunning(program_name);
Oct 05 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 05 Oct 2011 10:38:58 -0400, Dsmith <Dsmith nomail.com> wrote:

 In the core.thread library, there is a method isRunning() which takes a  
 thread.

 To make code more portable, rather than use a system call or getenv(),  
 how might
 isRunning() be adapted to check if a program is running?
 Ideally: isrunning(program_name);
It cannot. isRunning checks a local boolean, it does not do any OS queries. Now, once you have a reference to a running process, I'd say it's probably possible to add isRunning methods that call on the OS functions. Given a process ID, getting information about the process is pretty straightforward. I think this might be a good addition to std.process if it's not already in there. It's just the getting of the pid based on the name is not straightforward. -Steve
Oct 05 2011
next sibling parent "Regan Heath" <regan netmail.co.nz> writes:
On Wed, 05 Oct 2011 16:05:02 +0100, Steven Schveighoffer  
<schveiguy yahoo.com> wrote:

 On Wed, 05 Oct 2011 10:38:58 -0400, Dsmith <Dsmith nomail.com> wrote:

 In the core.thread library, there is a method isRunning() which takes a  
 thread.

 To make code more portable, rather than use a system call or getenv(),  
 how might
 isRunning() be adapted to check if a program is running?
 Ideally: isrunning(program_name);
It cannot. isRunning checks a local boolean, it does not do any OS queries. Now, once you have a reference to a running process, I'd say it's probably possible to add isRunning methods that call on the OS functions. Given a process ID, getting information about the process is pretty straightforward. I think this might be a good addition to std.process if it's not already in there. It's just the getting of the pid based on the name is not straightforward.
.. on unix systems. :p In the past I've had to parse "ps" output on various platforms. On Windows it's a great deal easier. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Oct 05 2011
prev sibling parent Kagamin <spam here.lot> writes:
Steven Schveighoffer Wrote:

 It's just the getting of the pid based on the name is not straightforward.
There's an open standard for this: http://en.wikipedia.org/wiki/Common_Information_Model_%28computing%29
Oct 05 2011