2 * SMSD PID file handling
4 /* Copyright (c) 2009 Michal Cihar <michal@cihar.com> */
5 /* Licensend under GNU GPL 2 */
10 #include <sys/types.h>
16 * Check existing PID file if it points to existing application.
18 void check_pid(const char *pid_file
)
24 file
= fopen(pid_file
, "r");
26 if (fscanf(file
, "%d", &other
) == 1) {
27 if (kill(other
, 0) == 0) {
29 "Another instance is running, please stop it first!\n");
32 fprintf(stderr
, "Stale lock file, ignoring!\n");
35 fprintf(stderr
, "Can not parse pidfile, ignoring!\n");
44 void write_pid(const char *pid_file
)
48 file
= fopen(pid_file
, "w");
50 fprintf(file
, "%d\n", getpid());
53 fprintf(stderr
, "Can not create pidfile!\n");
58 /* How should editor hadle tabs in this file? Add editor commands here.
59 * vim: noexpandtab sw=8 ts=8 sts=8: