2013-10-05 00:05:01 +05:30
|
|
|
'\" -*- coding: UTF-8 -*-
|
|
|
|
.\" Copyright (C) 1998 Miquel van Smoorenburg.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" This program is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU General Public License
|
|
|
|
.\" along with this program; if not, write to the Free Software
|
|
|
|
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
.\"
|
2019-09-21 11:47:05 +05:30
|
|
|
.TH PIDOF 1 "2019-09-21" "" "User Commands"
|
2013-10-05 00:05:01 +05:30
|
|
|
.SH NAME
|
|
|
|
pidof -- find the process ID of a running program.
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B pidof
|
|
|
|
.RB [ \-s ]
|
|
|
|
.RB [ \-c ]
|
|
|
|
.RB [ \-x ]
|
|
|
|
.RB [ \-o
|
|
|
|
.IR omitpid[,omitpid..] ]
|
|
|
|
.RB [ \-o
|
|
|
|
.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 ]
|
2013-10-05 00:05:01 +05:30
|
|
|
.B program
|
|
|
|
.RB [ program.. ]
|
|
|
|
.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
|
|
|
|
.IP \-s
|
|
|
|
Single shot - this instructs the program to only return one \fIpid\fP.
|
|
|
|
.IP \-c
|
|
|
|
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.
|
|
|
|
.IP \-x
|
|
|
|
Scripts too - this causes the program to also return process id's of
|
|
|
|
shells running the named scripts.
|
|
|
|
.IP "-o \fIomitpid\fP"
|
2013-10-14 19:08:33 +05:30
|
|
|
Tells \fIpidof\fP to omit processes with that process id. The special
|
|
|
|
pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP
|
|
|
|
program, in other words the calling shell or shell script.
|
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
|
|
|
.IP "-S \fIseparator\fP"
|
|
|
|
Use \fIseparator\fP as a separator put between pids. Used only when
|
|
|
|
more than one pids are printed for the program.
|
2019-09-21 11:47:05 +05:30
|
|
|
The \fI\-d\fR option is an alias for this option for sysvinit pidof
|
|
|
|
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-03-03 13:17:22 +05:30
|
|
|
.SH BUGS
|
|
|
|
When using the \fI\-x\fP option,
|
|
|
|
.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
|
|
|
|
Jaromir Capik <jcapik@redhat.com>
|