diff options
author | Aaron Ball <nullspoon@oper.io> | 2022-10-13 18:37:39 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2022-10-13 18:37:39 -0600 |
commit | 7a9e46793e4beef43654cee443d54a1a4299b77b (patch) | |
tree | dac3abc3beae316d0d195fcefa2e394dec965a85 | |
parent | 304ddad0a6d501189367ebdfc863eb7f542fbbc8 (diff) | |
download | psre-7a9e46793e4beef43654cee443d54a1a4299b77b.tar.gz psre-7a9e46793e4beef43654cee443d54a1a4299b77b.tar.xz |
Add -n,--noself option
This will filter out the pid of the current `psre` process to avoid
needed to do something like `grep -v` when doing things like bulk
killing processes (which wouldn't work anyways if no cmdline is
printed, which is default).
-rw-r--r-- | src/main.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -19,9 +19,11 @@ #include <string.h> #include <sys/types.h> #include <dirent.h> +#include <unistd.h> struct config { int print_cmdline; + int no_self; const char* regex; }; @@ -77,6 +79,9 @@ int pid_search(struct config* c) { read_cmdline(pathbuf, cmdbuf, 512); if(re_match(cmdbuf, (char*) c->regex) == 0) { + if(getpid() == pid && c->no_self == 1) + continue; + fputs(ent->d_name, stdout); if(c->print_cmdline) { fputc('\t', stdout); @@ -96,6 +101,7 @@ void gethelp() { " psre [options] regex\n\n" "Options:\n" " -c,--cmdline Print cmdline with each matching pid\n" + " -n,--noself Exclude current psre process from output\n" " -h,--help Print this helptext\n" ); } @@ -103,11 +109,14 @@ void gethelp() { int parseargs(struct config* c, int argc, char* argv[]) { int i = 1; c->print_cmdline = 0; + c->no_self = 0; c->regex = ".*"; while(i < argc) { if(strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--cmdline") == 0) { c->print_cmdline = 1; + } else if(strcmp(argv[i], "-n") == 0 || strcmp(argv[i], "--noself") == 0) { + c->no_self = 1; } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { gethelp(); return -1; |