2023-02-08 12:58:55 +05:30
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2018-2023 Jim Warner <james.warner@comcast.net>
|
|
|
|
.\" Copyright (c) 2019-2023 Craig Small <csmall@dropbear.xyz>
|
|
|
|
.\" Copyright (c) 2013 Jaromir Capik <jcapik@redhat.com>
|
|
|
|
.\" Copyright (c) 1998 Miquel van Smoorenburg
|
2013-10-05 00:05:01 +05:30
|
|
|
.\"
|
|
|
|
.\" This program is free software; you can redistribute it and/or modify
|
|
|
|
.\" it under the terms of the GNU General Public License as published by
|
|
|
|
.\" the Free Software Foundation; either version 2 of the License, or
|
|
|
|
.\" (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\"
|
2023-01-16 12:59:50 +05:30
|
|
|
.TH PIDOF 1 "2023-01-16" "" "User Commands"
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH NAME
|
2023-01-16 12:59:50 +05:30
|
|
|
pidof \- find the process ID of a running program
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH SYNOPSIS
|
|
|
|
.B pidof
|
|
|
|
.RB [ \-s ]
|
|
|
|
.RB [ \-c ]
|
2020-12-22 09:02:26 +05:30
|
|
|
.RB [ \-q ]
|
|
|
|
.RB [ \-w ]
|
2013-10-05 00:05:01 +05:30
|
|
|
.RB [ \-x ]
|
|
|
|
.RB [ \-o
|
2020-06-04 17:55:26 +05:30
|
|
|
.IR omitpid[,omitpid...]... ]
|
pidof: allow to change a separator put between pids
I frequency use pidof command with strace system call tracer.
strace can trace MULTIPLE processes specified with "-p $PID"
arguments like:
strace -p 1 -p 1030 -p 3043
Sometimes I want to do as following
strace -p $(pidof httpd)
However, above command line doesn't work because -p option
is needed for specifying a pid. pidof uses a whitespace as
a separator. For passing the output to strace, the separator
should be replaced with ' -p '.
This maybe not a special to my use case.
This commit introduces -S option that allows a user to specify a
separator the one wants.
$ ./pidof bash
./pidof bash
24624 18790 12786 11898 11546 10766 7654 5095
$ ./pidof -S ',' bash
./pidof -S ',' bash
24624,18790,12786,11898,11546,10766,7654,5095
$ ./pidof -S '-p ' bash
./pidof -S '-p ' bash
24624-p 18790-p 12786-p 11898-p 11546-p 10766-p 7654-p 5095
$ ./pidof -S ' -p ' bash
./pidof -S ' -p ' bash
24624 -p 18790 -p 12786 -p 11898 -p 11546 -p 10766 -p 7654 -p 5095
$ strace -p $(./pidof -S ' -p ' bash)
strace -p $(./pidof -S ' -p ' bash)
strace: Process 24624 attached
strace: Process 18790 attached
strace: Process 12786 attached
...
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-02-24 14:33:11 +05:30
|
|
|
.RB [ \-S
|
|
|
|
.IR separator ]
|
2023-01-16 12:59:50 +05:30
|
|
|
.I program
|
|
|
|
.IB [ program... ]
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH DESCRIPTION
|
|
|
|
.B Pidof
|
|
|
|
finds the process id's (pids) of the named programs. It prints those
|
|
|
|
id's on the standard output.
|
|
|
|
.SH OPTIONS
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP \fB\-s\fP
|
2013-10-05 00:05:01 +05:30
|
|
|
Single shot - this instructs the program to only return one \fIpid\fP.
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP \fB\-c\fP
|
2013-10-05 00:05:01 +05:30
|
|
|
Only return process ids that are running with the same root directory.
|
|
|
|
This option is ignored for non-root users, as they will be unable to check
|
|
|
|
the current root directory of processes they do not own.
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP \fB\-q\fP
|
2020-12-22 09:02:26 +05:30
|
|
|
Quiet mode, suppress any output and only sets the exit status accordingly.
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP \fB\-w\fP
|
2020-12-22 05:44:41 +05:30
|
|
|
Show also processes that do not have visible command line (e.g. kernel
|
|
|
|
worker threads).
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP \fB\-x\fP
|
2020-12-22 09:02:26 +05:30
|
|
|
Scripts too - this causes the program to also return process id's of
|
|
|
|
shells running the named scripts.
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP "\fB-o\fP \fIomitpid\fP"
|
|
|
|
Tells \fBpidof\fP to omit processes with that process id. The special
|
|
|
|
pid \fB%PPID\fP can be used to name the parent process of the \fBpidof\fP
|
2013-10-14 19:08:33 +05:30
|
|
|
program, in other words the calling shell or shell script.
|
2023-01-16 12:59:50 +05:30
|
|
|
.IP "\fB-S\fP \fIseparator\fP"
|
pidof: allow to change a separator put between pids
I frequency use pidof command with strace system call tracer.
strace can trace MULTIPLE processes specified with "-p $PID"
arguments like:
strace -p 1 -p 1030 -p 3043
Sometimes I want to do as following
strace -p $(pidof httpd)
However, above command line doesn't work because -p option
is needed for specifying a pid. pidof uses a whitespace as
a separator. For passing the output to strace, the separator
should be replaced with ' -p '.
This maybe not a special to my use case.
This commit introduces -S option that allows a user to specify a
separator the one wants.
$ ./pidof bash
./pidof bash
24624 18790 12786 11898 11546 10766 7654 5095
$ ./pidof -S ',' bash
./pidof -S ',' bash
24624,18790,12786,11898,11546,10766,7654,5095
$ ./pidof -S '-p ' bash
./pidof -S '-p ' bash
24624-p 18790-p 12786-p 11898-p 11546-p 10766-p 7654-p 5095
$ ./pidof -S ' -p ' bash
./pidof -S ' -p ' bash
24624 -p 18790 -p 12786 -p 11898 -p 11546 -p 10766 -p 7654 -p 5095
$ strace -p $(./pidof -S ' -p ' bash)
strace -p $(./pidof -S ' -p ' bash)
strace: Process 24624 attached
strace: Process 18790 attached
strace: Process 12786 attached
...
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-02-24 14:33:11 +05:30
|
|
|
Use \fIseparator\fP as a separator put between pids. Used only when
|
|
|
|
more than one pids are printed for the program.
|
2020-06-04 17:55:26 +05:30
|
|
|
The \fB\-d\fR option is an alias for this option for sysvinit
|
|
|
|
.B pidof
|
2019-09-21 11:47:05 +05:30
|
|
|
compatibility.
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH "EXIT STATUS"
|
|
|
|
.TP
|
|
|
|
.B 0
|
|
|
|
At least one program was found with the requested name.
|
|
|
|
.TP
|
|
|
|
.B 1
|
|
|
|
No program was found with the requested name.
|
|
|
|
|
2018-04-11 10:30:00 +05:30
|
|
|
.SH BUGS
|
2023-01-16 12:59:50 +05:30
|
|
|
When using the \fB\-x\fP option,
|
2018-04-11 10:30:00 +05:30
|
|
|
.B pidof
|
|
|
|
only has a simple method for detecting scripts and will miss scripts that,
|
|
|
|
for example, use env. This limitation is due to how the scripts look in
|
|
|
|
the proc filesystem.
|
|
|
|
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH SEE ALSO
|
|
|
|
.BR pgrep (1),
|
|
|
|
.BR pkill (1)
|
|
|
|
.SH AUTHOR
|
2023-01-16 12:59:50 +05:30
|
|
|
.UR jcapik@redhat.com
|
|
|
|
Jaromir Capik
|
|
|
|
.UE
|