lyn@carter.BCASDL.BOEING.COM ( Lyn Stewart ) (07/13/90)
Has anyone got a method for finding out if a process is running short of "ps -ef | grep processname" in a pipe. There must be a better way from within a c program. Lynwood A. Stewart Boeing Commercial Airplanes lyns@atc.boeing.com
jik@athena.mit.edu (Jonathan I. Kamens) (07/16/90)
In article <570001@carter.BCASDL.BOEING.COM>, lyn@carter.BCASDL.BOEING.COM ( Lyn Stewart ) writes: |> Has anyone got a method for finding out if a process is running short of |> "ps -ef | grep processname" in a pipe. There must be a better way from |> within a c program. The subject of your message says one thing, but the contents say another. Do you want to find the name of a process, or find out whether or not a particular process ID is still running? If the former, than running ps inside a popen is probably the best way to go about doing it. If the latter, then you can use the kill() function and send signal 0 to the process whose status you want to discover. If the process exists and is owned by you (or you are root), the kill() will return without error. If it exists and is owned by someone else and you are not root, it will return with EPERM. If it does not exist, it will return with ESRCH. Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710
kseshadr@quasar.intel.com (Kishore Seshadri) (07/17/90)
In article <570001@carter.BCASDL.BOEING.COM>, lyn@carter ( Lyn Stewart ) writes: > > >Has anyone got a method for finding out if a process is running short of >"ps -ef | grep processname" in a pipe. There must be a better way from >within a c program. > > If you're looking for some kind of a library function, I haven't seen one. You could do what ps does and look through the proc table, but its probably not worth the programming effort unless you're doing this real often. Kishore Seshadri =============================================================================== Kishore Seshadri (Speaking only for myself) Intel Corp., Santa Clara, CA CSNET: kseshadr@mipos3.intel.com ARPA: kseshadr%mipos3.intel.com@relay.cs.net UUCP:{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!kseshadr
pd@ixi.uucp (Paul Davey) (07/17/90)
In article <570001@carter.BCASDL.BOEING.COM> lyn@carter.BCASDL.BOEING.COM ( Lyn Stewart ) writes:
Has anyone got a method for finding out if a process is running short of
"ps -ef | grep processname" in a pipe. There must be a better way from
within a c program.
Well, for interactive use I use csh aliases, they should be easy enough to
move to (k)sh functions if you don't use csh. I've not needed to solve the
problem strictly or within a program.
This is what I use on sys5 machines,
alias psg 'ps -ef | sed -n -e "/sed -n -e /d\\
/\!$/p\\
/TIME COMMAND/p"'
Everything except the 'ps -ef' is ok on BSD. Change that to 'ps aux'
'psg pd' shows all processes containing the string pd.
--
Regards, pd@x.co.uk IXI Limited
Paul Davey pd@ixi.uucp 62-74 Burleigh St.
...!uunet!ixi!pd Cambridge U.K.
"These are interesting times" +44 223 462 131 CB1 1OJ