.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
-.TH PGREP "1" "2019-03-05" "procps-ng" "User Commands"
+.TH PGREP "1" "2020-04-24" "procps-ng" "User Commands"
.SH NAME
pgrep, pkill \- look up or signal processes based on name and other attributes
.SH SYNOPSIS
Match only the provided namespaces. Available namespaces:
ipc, mnt, net, pid, user,uts.
.TP
+\fB\-q\fR, \fB\-\-queue \fIvalue\fP
+Use
+.BR sigqueue(3)
+rather than
+.BR kill(2)
+and the value argument is used to specify
+an integer to be sent with the signal. If the receiving process has
+installed a handler for this signal using the SA_SIGINFO flag to
+.BR sigaction(2)
+, then it can obtain this data via the si_value field of the
+siginfo_t structure.
+.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.TP
.BR ps (1),
.BR regex (7),
.BR signal (7),
+.BR sigqueue (3),
.BR killall (1),
.BR skill (1),
.BR kill (1),
#include <regex.h>
#include <errno.h>
#include <getopt.h>
+#include <stdbool.h>
/* EXIT_SUCCESS is 0 */
/* EXIT_FAILURE is 1 */
static int opt_echo = 0;
static int opt_threads = 0;
static pid_t opt_ns_pid = 0;
+static bool use_sigqueue = false;
+static union sigval sigval = {0};
static const char *opt_delim = "\n";
static struct el *opt_pgrp = NULL;
}
if (i_am_pkill == 1) {
fputs(_(" -<sig>, --signal <sig> signal to send (either number or name)\n"), fp);
+ fputs(_(" -q, --queue <value> integer value to be sent with the signal\n"), fp);
fputs(_(" -e, --echo display what is killed\n"), fp);
}
fputs(_(" -c, --count count of matching processes\n"), fp);
{"echo", no_argument, NULL, 'e'},
{"ns", required_argument, NULL, NS_OPTION},
{"nslist", required_argument, NULL, NSLIST_OPTION},
+ {"queue", required_argument, NULL, 'q'},
{"runstates", required_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
if (-1 < sig)
opt_signal = sig;
/* These options are for pkill only */
- strcat (opts, "e");
+ strcat (opts, "eq:");
} else {
/* These options are for pgrep only */
strcat (opts, "lad:vw");
if (opt_nslist == NULL)
usage ('?');
break;
+ case 'q':
+ sigval.sival_int = atoi(optarg);
+ use_sigqueue = true;
+ break;
case 'h':
case '?':
usage (opt);
program_invocation_short_name);
}
+inline static int execute_kill(pid_t pid, int sig_num)
+{
+ if (use_sigqueue)
+ return sigqueue(pid, sig_num, sigval);
+ else
+ return kill(pid, sig_num);
+}
int main (int argc, char **argv)
{
int i;
int kill_count = 0;
for (i = 0; i < num; i++) {
- if (kill (procs[i].num, opt_signal) != -1) {
+ if (execute_kill (procs[i].num, opt_signal) != -1) {
if (opt_echo)
printf(_("%s killed (pid %lu)\n"), procs[i].str, procs[i].num);
kill_count++;