sysmgr

a simplistic service supervisor (deprecated)
git clone git://git.ckyln.com/~cem/sysmgr.git
Log | Files | Refs | README | LICENSE

commit 2a937333604fb4cbfbdef0811c8235504aaa2990
parent 75b69eba5d33e252822656b1bda2590d5830bc98
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed, 16 Sep 2020 20:13:28 +0300

checkprocess: add simple C utility to check processes

Diffstat:
Mutils/Makefile | 4++--
Autils/checkprocess.c | 31+++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/utils/Makefile b/utils/Makefile @@ -1,9 +1,9 @@ CC = cc HDR = util.h -SRC = util.c sysmgr-needs.c +SRC = util.c sysmgr-needs.c checkprocess.c OBJ = ${SRC:.c=.o} -BIN = sysmgr-needs +BIN = sysmgr-needs checkprocess all: ${BIN} diff --git a/utils/checkprocess.c b/utils/checkprocess.c @@ -0,0 +1,31 @@ +/* See LICENSE for copyright information */ +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <libgen.h> + +#include "util.h" + +static char *argv0; + +void +usage(void) +{ + fprintf(stderr, "usage: %s [pid]\n", argv0); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + argv0 = basename(argv[0]); + int pid; + + if (!argv[1] || sscanf(argv[1], "%d", &pid) != 1) + usage(); + + if (checkprocess(pid) == 0) + return 0; + else + return 1; +}