man-pages/man1/pgrep.1.html
2021-03-31 01:06:50 +01:00

348 lines
8.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PGREP</TITLE>
</HEAD><BODY>
<H1>PGREP</H1>
Section: User Commands (1)<BR>Updated: 2019-03-05<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
pgrep, pkill - look up or signal processes based on name and other attributes
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>pgrep</B>
[options] pattern
<BR>
<B>pkill</B>
[options] pattern
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>pgrep</B>
looks through the currently running processes and lists the process IDs which
match the selection criteria to stdout. All the criteria have to match.
For example,
<DL COMPACT>
<DT id="1"><DD>
$ pgrep -u root sshd
</DL>
<P>
will only list the processes called
<B>sshd</B>
AND owned by
<B>root</B>.
On the other hand,
<DL COMPACT>
<DT id="2"><DD>
$ pgrep -u root,daemon
</DL>
<P>
will list the processes owned by
<B>root</B>
OR
<B>daemon</B>.
<P>
<B>pkill</B>
will send the specified signal (by default
<B>SIGTERM</B>)
to each process instead of listing them on stdout.
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="3"><B>-</B><I>signal</I><DD>
<B>--signal</B> <I>signal</I>
Defines the signal to send to each matched process. Either the numeric or
the symbolic signal name can be used.
(<B>pkill</B>
only.)
<DT id="4"><B>-c</B>, <B>--count</B><DD>
Suppress normal output; instead print a count of matching processes. When
count does not match anything, e.g. returns zero, the command will return
non-zero value.
<DT id="5"><B>-d</B>, <B>--delimiter</B> <I>delimiter</I><DD>
Sets the string used to delimit each process ID in the output (by default a
newline).
(<B>pgrep</B>
only.)
<DT id="6"><B>-f</B>, <B>--full</B><DD>
The
<I>pattern</I>
is normally only matched against the process name. When
<B>-f</B>
is set, the full command line is used.
<DT id="7"><B>-g</B>, <B>--pgroup</B> <I>pgrp</I>,...<DD>
Only match processes in the process group IDs listed. Process group 0 is
translated into
<B>pgrep</B>'s
or
<B>pkill</B>'s
own process group.
<DT id="8"><B>-G</B>, <B>--group</B> <I>gid</I>,...<DD>
Only match processes whose real group ID is listed. Either the numerical or
symbolical value may be used.
<DT id="9"><B>-i</B>, <B>--ignore-case</B><DD>
Match processes case-insensitively.
<DT id="10"><B>-l</B>, <B>--list-name</B><DD>
List the process name as well as the process ID.
(<B>pgrep</B>
only.)
<DT id="11"><B>-a</B>, <B>--list-full</B><DD>
List the full command line as well as the process ID.
(<B>pgrep</B>
only.)
<DT id="12"><B>-n</B>, <B>--newest</B><DD>
Select only the newest (most recently started) of the matching processes.
<DT id="13"><B>-o</B>, <B>--oldest</B><DD>
Select only the oldest (least recently started) of the matching processes.
<DT id="14"><B>-P</B>, <B>--parent</B> <I>ppid</I>,...<DD>
Only match processes whose parent process ID is listed.
<DT id="15"><B>-s</B>, <B>--session</B> <I>sid</I>,...<DD>
Only match processes whose process session ID is listed. Session ID 0
is translated into
<B>pgrep</B>'s
or
<B>pkill</B>'s
own session ID.
<DT id="16"><B>-t</B>, <B>--terminal</B> <I>term</I>,...<DD>
Only match processes whose controlling terminal is listed. The terminal name
should be specified without the &quot;/dev/&quot; prefix.
<DT id="17"><B>-u</B>, <B>--euid</B> <I>euid</I>,...<DD>
Only match processes whose effective user ID is listed. Either the numerical
or symbolical value may be used.
<DT id="18"><B>-U</B>, <B>--uid</B> <I>uid</I>,...<DD>
Only match processes whose real user ID is listed. Either the numerical or
symbolical value may be used.
<DT id="19"><B>-v</B>, <B>--inverse</B><DD>
Negates the matching. This option is usually used in
<B>pgrep</B>'s
context. In
<B>pkill</B>'s
context the short option is disabled to avoid accidental usage of the option.
<DT id="20"><B>-w</B>, <B>--lightweight</B><DD>
Shows all thread ids instead of pids in
<B>pgrep</B>'s
context. In
<B>pkill</B>'s
context this option is disabled.
<DT id="21"><B>-x</B>, <B>--exact</B><DD>
Only match processes whose names (or command line if -f is specified)
<B>exactly</B>
match the
<I>pattern</I>.
<DT id="22"><B>-F</B>, <B>--pidfile</B> <I>file</I><DD>
Read
<I>PID</I>'s
from file. This option is perhaps more useful for
<B>pkill</B>
than
<B>pgrep</B>.
<DT id="23"><B>-L</B>, <B>--logpidfile</B><DD>
Fail if pidfile (see -F) not locked.
<DT id="24"><B>-r</B>, <B>--runstates</B> <I>D,R,S,Z,</I>...<DD>
Match only processes which match the process state.
<DT id="25"><B>--ns </B><I>pid</I><DD>
Match processes that belong to the same namespaces. Required to run as
root to match processes from other users. See --nslist for how to limit
which namespaces to match.
<DT id="26"><B>--nslist </B><I>name</I>,...<DD>
Match only the provided namespaces. Available namespaces:
ipc, mnt, net, pid, user,uts.
<DT id="27"><B>-V</B>, <B>--version</B><DD>
Display version information and exit.
<DT id="28"><B>-h</B>, <B>--help</B><DD>
Display help and exit.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>OPERANDS</H2>
<DL COMPACT>
<DT id="29"><I>pattern</I>
<DD>
Specifies an Extended Regular Expression for matching against the process
names or command lines.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>EXAMPLES</H2>
Example 1: Find the process ID of the
<B>named</B>
daemon:
<DL COMPACT>
<DT id="30"><DD>
$ pgrep -u root named
</DL>
<P>
Example 2: Make
<B>syslog</B>
reread its configuration file:
<DL COMPACT>
<DT id="31"><DD>
$ pkill -HUP syslogd
</DL>
<P>
Example 3: Give detailed information on all
<B>xterm</B>
processes:
<DL COMPACT>
<DT id="32"><DD>
$ ps -fp $(pgrep -d, -x xterm)
</DL>
<P>
Example 4: Make all
<B>chrome</B>
processes run nicer:
<DL COMPACT>
<DT id="33"><DD>
$ renice +4 $(pgrep chrome)
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>EXIT STATUS</H2>
<DL COMPACT>
<DT id="34">0<DD>
One or more processes matched the criteria. For pkill the process must also
have been successfully signalled.
<DT id="35">1<DD>
No processes matched or none of them could be signalled.
<DT id="36">2<DD>
Syntax error in the command line.
<DT id="37">3<DD>
Fatal error: out of memory etc.
</DL>
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
The process name used for matching is limited to the 15 characters present in
the output of /proc/<I>pid</I>/stat. Use the -f option to match against the
complete command line, /proc/<I>pid</I>/cmdline.
<P>
The running
<B>pgrep</B>
or
<B>pkill</B>
process will never report itself as a
match.
<A NAME="lbAJ">&nbsp;</A>
<H2>BUGS</H2>
The options
<B>-n</B>
and
<B>-o</B>
and
<B>-v</B>
can not be combined. Let
me know if you need to do this.
<P>
Defunct processes are reported.
<P>
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+ps">ps</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?7+regex">regex</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?1+killall">killall</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+skill">skill</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+kill">kill</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+kill">kill</A></B>(2)
<A NAME="lbAL">&nbsp;</A>
<H2>AUTHOR</H2>
Kjetil Torgrim Homme
<A NAME="lbAM">&nbsp;</A>
<H2>REPORTING BUGS</H2>
Please send bug reports to
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="38"><A HREF="#lbAB">NAME</A><DD>
<DT id="39"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="40"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="41"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="42"><A HREF="#lbAF">OPERANDS</A><DD>
<DT id="43"><A HREF="#lbAG">EXAMPLES</A><DD>
<DT id="44"><A HREF="#lbAH">EXIT STATUS</A><DD>
<DT id="45"><A HREF="#lbAI">NOTES</A><DD>
<DT id="46"><A HREF="#lbAJ">BUGS</A><DD>
<DT id="47"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="48"><A HREF="#lbAL">AUTHOR</A><DD>
<DT id="49"><A HREF="#lbAM">REPORTING BUGS</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:23 GMT, March 31, 2021
</BODY>
</HTML>