Re: How to check if 'mysqld' is running?
Re: How to check if 'mysqld' is running?
- Subject: Re: How to check if 'mysqld' is running?
- From: Charles Bennett <email@hidden>
- Date: Fri, 07 Dec 2001 13:19:09 -0500
[munched]
>
> (e.g. httpd, sendmail, mysqld..)?
>
> Related to this question . What is a sock file? What is a pid file? Is there
>
> a difference between pid and sock files?
A pid file is ususaly a plain old text file with the pid of the daemon
as the only text inside.
The very existance of the file (in /var/run/) should indicate that the daemon is running,
because the daemon is supposed to delete that file on the way "down" and create
it when the daemon starts.
Of course if the daemon dies the pid file might not be removed, so it's wise
to check the contents of the file against something like getpriority()
to see if it's really running..
Try this.. (I'm sure you can turn this into a method call or subroutine)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#define MYPID "/var/run/upsd.pid"
int main (int argc, const char * argv[]) {
int priority;
FILE *fp;
char inStr[80];
fp = fopen(MYPID,"r");
if ( fp != NULL ) {
fgets(inStr,80,fp);
fclose(fp);
if( inStr == NULL) {
fprintf(stderr,"BAD PID FILE\n");
return -1;
}
printf("pid = %i\n",atoi(inStr));
errno = 0;
priority = getpriority(PRIO_PROCESS,atoi(inStr));
printf("errno = %i\n",errno); //must check errno because -1 is a valid priority
if( errno ) {
printf("not running\n");
return 0;
}
printf("priority = %i\n",priority);
printf("IS running\n");
return 1;
} else {
printf("not running\n");
}
return 0;
}
>
> Can someone help me a little? Does someone know a similar project with
>
> source code available?
Let me know if you need more help.
>
> TIA,
>
> Martin
>
>
>
> P.S. Sorry for my bad english. Sorry for being stupid in *NIX things.
kine problem
>
> _______________________________________________
>
> cocoa-dev mailing list
>
> email@hidden
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
_______________________________________________
>
cocoa-dev mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev