C system call to check for a process by name (something similar to ps)

C system call to check for a process by name (something similar to ps)

Post by jlee » Sat, 06 Dec 1997 04:00:00



Is there a C system call which can be called in a C program and
used to check whether a process is running? I want to be able
to query the processes running on the system by the name of the
process. I want something similar to "ps".

Thanks in advance.

Jerry Lee

 
 
 

C system call to check for a process by name (something similar to ps)

Post by Andrew Giert » Sat, 06 Dec 1997 04:00:00


 jlee> Is there a C system call which can be called in a C program and
 jlee> used to check whether a process is running?

No.

 jlee> I want to be able to query the processes running on the system
 jlee> by the name of the process. I want something similar to "ps".

Use ps (see example in FAQ, which also contains three examples of how
to do it *without* using ps, pointing out the total non-portability of
such code).

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

C system call to check for a process by name (something similar to ps)

Post by Johan Bengtsso » Tue, 09 Dec 1997 04:00:00


I Think that the easiest way to do this is to use popen to call ps,
and then parse the output. That should also be more portable than
traversing kernel datastructures, /proc files and such.

        / Johan

--
Civilization is the limitless multiplication of unnecessary necessities.
        --Mark Twain

 
 
 

1. Checking # of Process, ReStart a Process and Call another script

I have two questions and I am spending the whole day trying to figure
it out and decided to ask the expert.

1) My eval [eval $countRMI1098 -lt 3 ] does not work. Could you tell
me where I have to change. I search the deja.com but I don't see any
related subject.
2) I have cmrstart1098 file that I want to call in my korn shell
script. How could I do that? The cmrstart would have this command -
nohup rmiregistry 1098 > cmrlog1098.txt&

Thank for you help
Joe

#!/bin/ksh
countRMI1098=`ps -ef | grep -v grep | grep 1098 | wc`


messageJavaCoreDump="BOOGUS ! Just a test only.\n  Java Application
has a Core Dump.\nPlease restart all RMIs"
messageRMI1098="BOOGUS ! Just a test only.\nCMR 1098 RMIs were down
and have been restarted.\n"

if [ eval $countRMI1098 -lt 3 ]
   then
        ps -ef | grep -v grep | grep 1098 | awk '{print $2}' | xargs
kill
        cmrstart1098  
            echo messageRMI1098  | mail -s"RMI 1098 Restarted"  $notifyCMR
   else
        echo messageRMI1098  | mail -s"Everything is Okay"  $notifyCMR
fi

2. Does FreeBSD support OnStream IDE tape drives?

3. system call to get calling processes tty?

4. Apache and Netscape Gold

5. System Call, Library Call and Process Size

6. IBM 4693 series cash registers

7. system call starting next process before first process is finished.

8. recording PC keystrokes with hardware device

9. How I could add a new system call to linux or modify a system calls

10. How to use open system call in a new system call

11. check runing process with ps & grep

12. "Interrupted system call" at "low level" - system calls

13. process checking via grep from ps command