From 87ee5ec584c21dab5691f40fbcdf0a36ee53a2c2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Sep 2013 23:51:02 +0100 Subject: [PATCH] Added pid plugin --- pid/Makefile | 11 +++++++++++ pid/pid.c | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pid/Makefile create mode 100644 pid/pid.c diff --git a/pid/Makefile b/pid/Makefile new file mode 100644 index 0000000..4124b99 --- /dev/null +++ b/pid/Makefile @@ -0,0 +1,11 @@ +all: pid.so + +%.so:%.o + $(CC) -shared -fpic -lprofanity -o $@ $^ + +%.o:%.c + $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ + -Wall -Wextra -lprofanity -pedantic -c -o $@ $< + +clean: + $(RM) pid.so diff --git a/pid/pid.c b/pid/pid.c new file mode 100644 index 0000000..33cafb2 --- /dev/null +++ b/pid/pid.c @@ -0,0 +1,22 @@ +#include +#include +#include + +#include + +void +cmd_pid(char **args) +{ + pid_t pid = getpid(); + pid_t ppid = getppid(); + char buf[50]; + sprintf(buf, "PID: %d, parent PID: %d", pid, ppid); + prof_cons_show(buf); + prof_cons_alert(); +} + +void +prof_init(const char * const version, const char * const status) +{ + prof_register_command("/pid", 0, 0, "/pid", "Get process ID", "Get process ID", cmd_pid); +}