|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
|
Command pgrep is a command line utility similar to ps It was initially written for Solaris 7 operating system. Later it was reimplementation for all major OS that have /proc pseudo filesystem including Linux, BSD and HP-UX 11.3.
|
Options are identical with those implemented on Solaris, so Solaris documentation can be used for Linux pgrep.
Like in ps process name can be specified with extended regular expression patterns, and, by default, returns their ID. Functionally, the pgrep command combines the ps command with the grep command.
The syntax:
pgrep [-option] pattern
Options | Description |
---|---|
- l | long listings (name of the profess and its PID) |
-g pgrplist | Matches the processes with the process group ID. |
-G gidlist | Matches the active processes with the group ID(s) specified in the command line. For example, if you are searching for processes running with the group ID sysman, specify the command pgrep G sysman. |
-d delim | Specifies a delimiter for separating PIDs. |
-n | Matches the most recent process. |
-P ppidlist | The processes are matched with the parent process ID in the listing. |
-s sidlist | The processes are matched with the session ID in the list. |
-t termlist | Matches the terminal on which the process is running. |
-u euidlist | Matches processes with the effective used ID in the list. The effective uid is the uid of the executable file when the SUID of the file is set. |
-U uidlist | Matches processes with the real uid in the list. The real uid is the uid that the user uses when starting a task or a process. |
-v | Matches all processes except those that meet the specified criteria in the command line. |
-f | Matches pattern against full arguments rather than the name of the executable file. |
-x | Matches the processes that exactly match the specified pattern. |
The following example displays the process ID for the process sh:
$ pgrep sh 3 8027 307 765 762 6488 7970 8147 8150
The following command displays the process ID of all those processes matching the in pattern:
$ pgrep in* 1 59 111 118 156The pgrep command with the l option displays the name of the processes, which contains the string in along with their PIDs.
$ pgrep -l in 1 init 111 in.routed 118 in.ndpd 156 inetd 133 rpcbind
The following command displays the processes owned by user James:
$ pgrep -u james 1459 1464 $
You can combine options. In the following example, both the l and the u options are used together with the pgrep command to display the names of all the processes run by user James, along with his process ID.
$ pgrep -l -u james 1459 sh 1464 csh
The -d option is used to specify a delimiter for separating PIDs when more than one process ID is tested in the output of the pgrep command. The following example uses delimiters for the listed processes for the user James.
$ pgrep d";" u james 951; 1042; 1051
NOTE
You can specify more than one user ID by using a comma (,) as a field separator.
pgrep's default behaviour (returning the process identifier(s) of the named task(s)) is invoked by typing:
pgrep taskname
This is roughly equivalent to the following command:
ps ax |
grep
taskname | grep -v grep |
awk '{print $1}'
Hence, pgrep simplifies an otherwise complex task.
pgrep also has additional functionality, e.g.:
pgrep -l -G other
pgrep -v -u root
Examples from man page
Example 1: Find the process ID of the named daemon:
$ pgrep -u root named
Example 2: Make syslog reread its configuration file:
$ pkill -HUP syslogd
Example 3: Give detailed information on all xterm processes:
$ ps -fp $(pgrep -d, -x xterm)
Example 4: Make all netscape processes run nicer:
$ renice +4 `pgrep netscape`
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
"gev_d" <gdelvalle...gmail.com> writes:
> Now i use pgrep alot, but I'd like to see what options the process is
> running with. for example, let's say I'm running named, but I started
> it with the wrong conf file, how would I be able to see this with
> pgrep ( if that is possible )?How about something like this?
% ps -fp `pgrep -d, named`
James Carlson, KISS Network <james.d.carlson...sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677gev_d <gdelvalle...gmail.com> wrote:
> Hi All,
> I used to use ps -ef | grep process_name to find if a process was
> running. What i liked about this was that it showed the whole command
> line argument ( switches and values and all)pgrep -f
Daniel
attributes
[-t term,...] [pattern]
pkill [-signal] [-fvx] [-n|-o] [-P ppid,...] [-g pgrp,...]
[-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...]
[-t term,...] [pattern]
pgrep -u root sshd
will only list the processes called sshd AND owned by root. On the other hand,
pgrep -u
root,daemon
will list the processes owned by root OR daemon.
pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.
unix$ pgrep
-
u root named
Example 2: Make syslog reread its configuration file:
unix$
pkill -HUP syslogd
Example 3: Give detailed information on all xterm processes:
unix$ ps -fp $(pgrep -d, -x xterm)
Example 4: Make all netscape processes run nicer:
unix$ renice +4 'pgrep netscape'
The running pgrep or pkill process will never report itself as a match.
Defunct processes are reported.
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: March 12, 2019