Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!novavax!infocenter!mhoffman From: mhoffman@infocenter.UUCP (Mike Hoffman) Newsgroups: comp.unix.questions Subject: How to tell if a process is active? Keywords: process Message-ID: <2727@infocenter.UUCP> Date: 14 Jun 89 20:53:55 GMT Organization: Gould CSD, Fort Lauderdale, FL Lines: 46 I have an application in which I need to check to see if a process is currently active. The only method I have been able to devise is the "#" option of "ps", as in "ps #1234" which will print out a header, then the information on process 1234: % ps #1234 PID TT STAT TIME COMMAND 1234 117 IW 0:00 foo bar baz If process 1234 is not active, I get just the first line (the column headers), and there is nothing else. What I do, more or less, is: isactive(pid) open pipe fork if (child) redirect stdout to pipe execl ("bin/ps","ps","#pid",0) else read(pipe,sizeof(header line)) if (anything else to read) return(process is active) else return(process is not active) This seems terribly clumsy, and I'm sure there is a better way :-( It works, and seems dependable so far, but it seems to me that if "ps #1234" can do it, then I should be able to do it as well. Any help or suggestions will be appreciated. I hope this won't generate as many answers as "what does g/re/p mean?", but send answers e-mail, if possible - I'll summarize if volume warrants it. m/ik/e ---- UUCP: {uunet,codas!novavax,sun,pur-ee}!gould!mhoffman Michael J. Hoffman "My opinions cannot be confused Manufacturing Engineering with those of my employer, as Encore Computer Corporation I don't even know what those opinions might be."