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); +}