|
|
c65b29 |
From d9b3415d2a761cb7669a67f5309665335d5eb4c4 Mon Sep 17 00:00:00 2001
|
|
|
c65b29 |
From: rpm-build <rpm-build>
|
|
|
c65b29 |
Date: Mon, 9 Nov 2020 16:10:22 +0100
|
|
|
c65b29 |
Subject: [PATCH] New '-w' option for kernel workers.
|
|
|
c65b29 |
|
|
|
c65b29 |
---
|
|
|
c65b29 |
pidof.1 | 3 +++
|
|
|
c65b29 |
pidof.c | 17 ++++++++++++-----
|
|
|
c65b29 |
2 files changed, 15 insertions(+), 5 deletions(-)
|
|
|
c65b29 |
|
|
|
c65b29 |
diff --git a/pidof.1 b/pidof.1
|
|
|
c65b29 |
index 1368704..c85c088 100644
|
|
|
c65b29 |
--- a/pidof.1
|
|
|
c65b29 |
+++ b/pidof.1
|
|
|
c65b29 |
@@ -45,6 +45,9 @@ the current root directory of processes they do not own.
|
|
|
c65b29 |
.IP \-x
|
|
|
c65b29 |
Scripts too - this causes the program to also return process id's of
|
|
|
c65b29 |
shells running the named scripts.
|
|
|
c65b29 |
+.IP \-w
|
|
|
c65b29 |
+Show also processes that do not have visible command line (e.g. kernel
|
|
|
c65b29 |
+worker threads).
|
|
|
c65b29 |
.IP "-o \fIomitpid\fP"
|
|
|
c65b29 |
Tells \fIpidof\fP to omit processes with that process id. The special
|
|
|
c65b29 |
pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP
|
|
|
c65b29 |
diff --git a/pidof.c b/pidof.c
|
|
|
c65b29 |
index 94e19bb..7fdf27a 100644
|
|
|
c65b29 |
--- a/pidof.c
|
|
|
c65b29 |
+++ b/pidof.c
|
|
|
c65b29 |
@@ -55,6 +55,8 @@ static char *program = NULL;
|
|
|
c65b29 |
static int opt_single_shot = 0; /* -s */
|
|
|
c65b29 |
static int opt_scripts_too = 0; /* -x */
|
|
|
c65b29 |
static int opt_rootdir_check = 0; /* -c */
|
|
|
c65b29 |
+static int opt_with_workers = 0; /* -w */
|
|
|
c65b29 |
+
|
|
|
c65b29 |
|
|
|
c65b29 |
static char *pidof_root = NULL;
|
|
|
c65b29 |
|
|
|
c65b29 |
@@ -69,6 +71,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
|
|
|
c65b29 |
fputs(_(" -s, --single-shot return one PID only\n"), fp);
|
|
|
c65b29 |
fputs(_(" -c, --check-root omit processes with different root\n"), fp);
|
|
|
c65b29 |
fputs(_(" -x also find shells running the named scripts\n"), fp);
|
|
|
c65b29 |
+ fputs(_(" -w, --with-workers show kernel workers too\n"), fp);
|
|
|
c65b29 |
fputs(_(" -o, --omit-pid <PID,...> omit processes with PID\n"), fp);
|
|
|
c65b29 |
fputs(_(" -S, --separator SEP use SEP as separator put between PIDs"), fp);
|
|
|
c65b29 |
fputs(USAGE_SEPARATOR, fp);
|
|
|
c65b29 |
@@ -142,7 +145,6 @@ static void select_procs (void)
|
|
|
c65b29 |
static int size = 0;
|
|
|
c65b29 |
char *cmd_arg0, *cmd_arg0base;
|
|
|
c65b29 |
char *cmd_arg1, *cmd_arg1base;
|
|
|
c65b29 |
- char *stat_cmd;
|
|
|
c65b29 |
char *program_base;
|
|
|
c65b29 |
char *root_link;
|
|
|
c65b29 |
char *exe_link;
|
|
|
c65b29 |
@@ -168,10 +170,9 @@ static void select_procs (void)
|
|
|
c65b29 |
}
|
|
|
c65b29 |
}
|
|
|
c65b29 |
|
|
|
c65b29 |
- if (!is_omitted(task.XXXID)) {
|
|
|
c65b29 |
+ if (!is_omitted(task.XXXID) && ((task.cmdline && *task.cmdline) || opt_with_workers)) {
|
|
|
c65b29 |
|
|
|
c65b29 |
cmd_arg0 = (task.cmdline && *task.cmdline) ? *task.cmdline : "\0";
|
|
|
c65b29 |
- stat_cmd = task.cmd ? task.cmd : "\0";
|
|
|
c65b29 |
|
|
|
c65b29 |
/* processes starting with '-' are login shells */
|
|
|
c65b29 |
if (*cmd_arg0 == '-') {
|
|
|
c65b29 |
@@ -193,7 +194,7 @@ static void select_procs (void)
|
|
|
c65b29 |
!strcmp(program_base, cmd_arg0) ||
|
|
|
c65b29 |
!strcmp(program, cmd_arg0) ||
|
|
|
c65b29 |
|
|
|
c65b29 |
- !strcmp(program, stat_cmd) ||
|
|
|
c65b29 |
+ (opt_with_workers && !strcmp(program, task.cmd)) ||
|
|
|
c65b29 |
|
|
|
c65b29 |
!strcmp(program, exe_link_base) ||
|
|
|
c65b29 |
!strcmp(program, exe_link))
|
|
|
c65b29 |
@@ -293,13 +294,14 @@ int main (int argc, char **argv)
|
|
|
c65b29 |
int first_pid = 1;
|
|
|
c65b29 |
|
|
|
c65b29 |
const char *separator = " ";
|
|
|
c65b29 |
- const char *opts = "scnxmo:S:?Vh";
|
|
|
c65b29 |
+ const char *opts = "scnxwmo:S:?Vh";
|
|
|
c65b29 |
|
|
|
c65b29 |
static const struct option longopts[] = {
|
|
|
c65b29 |
{"check-root", no_argument, NULL, 'c'},
|
|
|
c65b29 |
{"single-shot", no_argument, NULL, 's'},
|
|
|
c65b29 |
{"omit-pid", required_argument, NULL, 'o'},
|
|
|
c65b29 |
{"separator", required_argument, NULL, 's'},
|
|
|
c65b29 |
+ {"with-workers", no_argument, NULL, 'w'},
|
|
|
c65b29 |
{"help", no_argument, NULL, 'h'},
|
|
|
c65b29 |
{"version", no_argument, NULL, 'V'},
|
|
|
c65b29 |
{NULL, 0, NULL, 0}
|
|
|
c65b29 |
@@ -325,6 +327,9 @@ int main (int argc, char **argv)
|
|
|
c65b29 |
case 'x':
|
|
|
c65b29 |
opt_scripts_too = 1;
|
|
|
c65b29 |
break;
|
|
|
c65b29 |
+ case 'w':
|
|
|
c65b29 |
+ opt_with_workers = 1;
|
|
|
c65b29 |
+ break;
|
|
|
c65b29 |
case 'c':
|
|
|
c65b29 |
if (geteuid() == 0) {
|
|
|
c65b29 |
opt_rootdir_check = 1;
|
|
|
c65b29 |
@@ -358,6 +363,8 @@ int main (int argc, char **argv)
|
|
|
c65b29 |
|
|
|
c65b29 |
program = argv[optind++];
|
|
|
c65b29 |
|
|
|
c65b29 |
+ if (*program == '\0') continue;
|
|
|
c65b29 |
+
|
|
|
c65b29 |
select_procs(); /* get the list of matching processes */
|
|
|
c65b29 |
|
|
|
c65b29 |
if (proc_count) {
|
|
|
c65b29 |
--
|
|
|
c65b29 |
2.25.4
|
|
|
c65b29 |
|