From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
To: linux-c-programming@vger.kernel.org
Subject: Re: Check if a process exists? (EXTENDING THE QUESTION)
Date: Mon, 11 Apr 2005 09:59:58 +0800 [thread overview]
Message-ID: <4259DA1E.9000409@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <20050409_015010_024210.lucianolnx@ig.com.br>
is the daemon/application name unique? maybe u can use a script that
makes use of the top-command.
or maybe u can make use of the pstat_getproc() c function.(but im not
sure if there's a pstat_getproc
func in linux... im using hpux on itanium)
the code below relies on the fact that at any given moment, there is
only one instance of the
application running... the code is just a simple-search-and-print.
------------------------------------------------------
struct pst_status * psa = NULL;
struct pst_status * prc = NULL;
struct pst_dynamic psd;
long nproc = 0;
long i;
if ( pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1 )
(void)perror("pstat_getdynamic failed");
nproc = psd.psd_activeprocs;
psa = (struct pst_status *)malloc(nproc * sizeof(struct pst_status));
if ( pstat_getproc(psa, sizeof(struct pst_status), nproc, 0) == -1 )
(void)perror("pstat_getproc failed");
// Report the process info as required
prc = (struct pst_status *)psa;
for (i=0; i < nproc; i++)
{
if ( strcmp( prc->pst_cmd, "APPLICATION NAME" ) == 0 )
{
(void)printf("PID IS %d \n", prc->pst_pid);
break;
}
++prc;
}
------------------------------------------------------
lucianolnx wrote:
>Today, what are the bests ways to know if a deamon is running without
>knowing its PID ?
>
>My old technique (used until now), is based on recovering the PID saved by
>the own process in a special and known location (like a file), almost all
>times persisted (PERSISTENCE IS A PROBLEM).
>
>Luciano
>
>
>
>On Tue, 1 Mar 2005, Hareesh Nagarajan wrote:
>
>
>
>>Hi,
>>
>>Can a process check if a given PID exists or not? In other words can a
>>process check if an unrelated process is alive? Is there any system
>>call that does this?
>>
>>
>>
>Use kill() with a second argument being zero.
>
> if (kill(pid, 0) == -1)
> {
> /* Process is not there. */
> }
> else
> {
> /* Process is alive. */
> }
>
>Holger
>
>
prev parent reply other threads:[~2005-04-11 1:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-09 1:50 Check if a process exists? (EXTENDING THE QUESTION) lucianolnx
2005-04-09 7:24 ` M.Baris Demiray
2005-04-11 1:59 ` Ron Michael Khu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4259DA1E.9000409@hq.ntsp.nec.co.jp \
--to=ronkhu@ntsp.nec.co.jp \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).