Sujet : Re: Basic ps Tips
De : jerry (at) *nospam* example.invalid (Jerry Peters)
Groupes : comp.unix.shellDate : 02. Aug 2024, 01:19:58
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8h8ne$2eq4k$1@dont-email.me>
References : 1 2
User-Agent : tin/2.4.5-20201224 ("Glen Albyn") (Linux/6.6.41 (x86_64))
Lawrence D'Oliveiro <
ldo@nz.invalid> wrote:
On Sat, 27 Jul 2024 00:40:49 -0000 (UTC), I wrote:
Another useful command to use with ps is pgrep(1)
<https://man7.org/linux/man-pages/man1/pgrep.1.html>
If you are expecting more than one process to match your criteria, it
is easy enough to use the ???-d,??? option to comma-separate them. Then the
output becomes acceptable to the ???-p??? option in ps, e.g.
ps -p$(pgrep -d, bash) -wwo pid,ppid,lstart,tty,etime,cmd
to report all the bash sessions I have running (quite a lot). The ???ww???
says not to truncate the output, which is handy for long command lines.
Or just use ps -C <command>:
ps -p$(pgrep -d, bash) -wwo pid,ppid,lstart,tty,etime,cmd
PID PPID STARTED TT ELAPSED CMD
1332 1327 Thu Jul 18 10:12:28 2024 pts/1 14-10:02:20 bash
2019 2018 Thu Jul 18 20:20:31 2024 pts/3 13-23:54:17 bash
2237 2236 Thu Jul 18 20:39:49 2024 pts/4 13-23:34:59 bash
10821 10820 Sat Jul 20 14:45:57 2024 pts/6 12-05:28:51 bash
20342 20341 Wed Jul 31 09:58:54 2024 pts/7 1-10:15:54 bash
ps -C bash -wwo pid,ppid,lstart,tty,etime,cmd
PID PPID STARTED TT ELAPSED CMD
1332 1327 Thu Jul 18 10:12:28 2024 pts/1 14-10:02:35 bash
2019 2018 Thu Jul 18 20:20:31 2024 pts/3 13-23:54:32 bash
2237 2236 Thu Jul 18 20:39:49 2024 pts/4 13-23:35:14 bash
10821 10820 Sat Jul 20 14:45:57 2024 pts/6 12-05:29:06 bash
20342 20341 Wed Jul 31 09:58:54 2024 pts/7 1-10:16:09 bash
Does noone know about -C? I keep seeing things like 'ps -ef | grep
<something> in scripts to see if <something is running, rather than
using 'ps -C'.
Jerry