comp.lang.ada
 help / color / mirror / Atom feed
* How to query active processes from Ada
@ 1997-01-03  0:00 James d'Eon
  1997-01-03  0:00 ` Christopher Green
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: James d'Eon @ 1997-01-03  0:00 UTC (permalink / raw)



Hi,
  I have a situation where I am trying to determine if a process is active. I 
do know the process ID. This is pretty simple from the command line by using 
the 'ps' command, but I have not been successful yet in implementing this in 
Ada. Has anyone out there tried this, or have any ideas to point me in the 
right direction? 

Thanks,
  James




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

* Re: How to query active processes from Ada
  1997-01-03  0:00 How to query active processes from Ada James d'Eon
@ 1997-01-03  0:00 ` Christopher Green
  1997-01-03  0:00 ` Ted Dennison
  1997-01-06  0:00 ` David Emery
  2 siblings, 0 replies; 4+ messages in thread
From: Christopher Green @ 1997-01-03  0:00 UTC (permalink / raw)



In article <5aj97p$a9m@news.spar.ca>, James d'Eon <james.deon@prior.ca> wrote:
>Hi,
>  I have a situation where I am trying to determine if a process is active. I 
>do know the process ID. This is pretty simple from the command line by using 
>the 'ps' command, but I have not been successful yet in implementing this in 
>Ada. Has anyone out there tried this, or have any ideas to point me in the 
>right direction? 
>
>Thanks,
>  James

This is system-dependent, but there is a solution that will work for any host
(most UNIX System V hosts) that has the /proc filesystem.  Every process on
such a host has a file named /proc/nnnnn, where nnnnn is the process ID.

If you have POSIX bindings, the function POSIX_Files.Is_File will return TRUE
if there is a file of the given name.  This is the best way; it will work
even if you are not the superuser.

If you do not, try opening the file /proc/nnnnn, where nnnnn is the process ID.
This will work only if you have the same user ID as the process you are testing,
or if you are the superuser.

If you do not have a /proc filesystem, there are still host-dependent ways to
check up on a process, but they are complex and involve reading kernel memory.
Discussion of these ways is beyond the scope of this post; if it is important
to you, get the source code for "top", or ask on comp.unix.programmer.

Chris Green                                  Email cgreen@atc.com
Advanced Technology Center                   Phone (714) 583-9119
22982 Mill Creek Drive                                   ext. 220
Laguna Hills, CA 92653                       Fax   (714) 583-9213




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

* Re: How to query active processes from Ada
  1997-01-03  0:00 How to query active processes from Ada James d'Eon
  1997-01-03  0:00 ` Christopher Green
@ 1997-01-03  0:00 ` Ted Dennison
  1997-01-06  0:00 ` David Emery
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 1997-01-03  0:00 UTC (permalink / raw)



James d'Eon wrote:
> 
> Hi,
>   I have a situation where I am trying to determine if a process is active. I
> do know the process ID. This is pretty simple from the command line by using
> the 'ps' command, but I have not been successful yet in implementing this in
> Ada. Has anyone out there tried this, or have any ideas to point me in the
> right direction?

That's a UNIX question, not an Ada question. Check the Unix man pages on
your system (sections 2 and 3). Just call the appropriate Unix system
calls from your Ada program.

Alternatively, you could ask in one of the Unix newsgroups.

-- 
T.E.D.          
             |  Work - mailto:dennison@escmail.orl.lmco.com  |
             |  Home - mailto:dennison@iag.net               |
             |  URL  - http://www.iag.net/~dennison          |




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

* Re: How to query active processes from Ada
  1997-01-03  0:00 How to query active processes from Ada James d'Eon
  1997-01-03  0:00 ` Christopher Green
  1997-01-03  0:00 ` Ted Dennison
@ 1997-01-06  0:00 ` David Emery
  2 siblings, 0 replies; 4+ messages in thread
From: David Emery @ 1997-01-06  0:00 UTC (permalink / raw)



The short answer is to send SIGNULL to the process with kill().  

Naturally this is supported by POSIX/Ada:
	
	with POSIX, POSIX_Signals, POSIX_Process_Identification;
	function Process_Exists 
	  (Pid : in Posix_Process_Identification.Process_Id) 
		return Boolean is
        begin
	   POSIX_Signals.Send_Signal
	     (Process => Pid,
	      Sig => POSIX_Signals.Signal_Null);
	   -- returns normally if Process exists.  
	   -- if process does not exist, or is not 'killable' by the
	   -- caller, raises POSIX_Error.
	   return True;
	exception
           when POSIX.POSIX_Error =>
	       return False;
	   when others =>
	        raise;
 	end Process_Exists;
	

				dave
-- 
<.sig is away on vacation>





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

end of thread, other threads:[~1997-01-06  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-03  0:00 How to query active processes from Ada James d'Eon
1997-01-03  0:00 ` Christopher Green
1997-01-03  0:00 ` Ted Dennison
1997-01-06  0:00 ` David Emery

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox