My way to check if a progam is already running
- From: Jan Panteltje <pNaonStpealmtje@xxxxxxxxx>
- Date: Tue, 19 Jun 2007 21:35:02 GMT
Lockfiles are bad, they show up at times as stale,
and then prevent your program to run.
/* This assumes there is a directory ~/.MyProgram/
struct passwd *userinfo;
char temp[4096];
FILE *fptr;
int a, b;
/* get user info */
userinfo = getpwuid(getuid() );
/* get home directory */
home_dir = strsave(userinfo -> pw_dir);
/* test if already a MyProgram running */
sprintf(temp, "pidof MyProgram > %s/.MyProgram/pids", home_dir);
ftr = popen(temp, "w");
pclose(ftr);
sprintf(temp, "%s/.MyProgram/pids", home_dir);
fptr = fopen(temp, "r");
if(fptr)
{
a = fscanf(fptr, "%d %d", &b, &b);
fclose(fptr);
if(a == 2)
{
fprintf(stderr, "MyProgram: An other MyProgram is already running, aborting.\n");
exit(1);
}
}
---------------------------------------------------------------------------------------------
What do you think, this good?
.
- Follow-Ups:
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- Prev by Date: Re: select()/write() semantics
- Next by Date: Re: select()/write() semantics
- Previous by thread: developing UART drivers on Linux?
- Next by thread: Re: My way to check if a progam is already running
- Index(es):
Relevant Pages
|