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,Use kill() with a second argument being zero.
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?
if (kill(pid, 0) == -1) { /* Process is not there. */ } else { /* Process is alive. */ }
Holger
- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
