aboutsummaryrefslogtreecommitdiff
path: root/src/com_status.c
blob: e0e68c7b4eb2a7e8c2597c8bb58bd963edf818cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* This file is part of genrc
Copyryght (C) 2018 Sergey Poznyakoff
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
*/
#include "genrc.h"

int
com_status(void)
{
	PIDLIST pids;
	int rc;

	pidlist_init(&pids);
	rc = get_pid_list(genrc_pid_closure, &pids);
	if (rc == 0) {
		if (pids.pidc == 0)
			printf("%s is not running\n", genrc_program);
		else {
			printf("%s is running ", genrc_program);
			if (pids.pidc == 1) {
				printf("(pid %lu)",
				       (unsigned long) pids.pidv[0]);
			} else {
				int i;
				int delim = ' ';
				printf("(pids");
				for (i = 0; i < pids.pidc; i++) {
					printf("%c%lu", delim,
					       (unsigned long) pids.pidv[i]);
					delim = ',';
				}
				putchar(')');
			}
			putchar('\n');
		}	
	} else {
		printf("status unknown\n");
	}
	return 0;
}

			

Return to:

Send suggestions and report system problems to the System administrator.