LINUX.ORG.RU
ФорумAdmin

Проблема с pgrep

 ,


0

1
kill -9 $(pgrep -f "${TARGET}") #, где TARGET - это notification-daemon, но есть earlyroom, в котором в строке запуска есть |kbdd|notification-daemon|numlockx| И, конечно же, pgrep "ловит" pid earlyroom. Как этого избежать?

Есть такой вариант:

kill -9 $(ps ax | grep "${TARGET}" | grep -vE 'grep|earlyoom' | awk '{print $1}')

Но он не универсальный. Мало ли что появится еще в процессах. Как сделать универсальный вариант?

Вообще это ахтунг, что в pgrep нет возможности применять регулярки, чтобы сделать типа ^notification-daemon$ или ^notification-daemon хотя бы

UPD: Кстати, еще забыл добавить, что pgrep -f умеет в поиск сабпроцессов

★★★

Последнее исправление: serg002 (всего исправлений: 2)
Ответ на: комментарий от anonymous
pgrep -f "([^\s]+/)?notification-daemon"
1107
5338
pgrep -f "([\S]+/)?$notification-daemon\b"
1101
1105
1107
1137
4002
4010
4131
4414
4535
4701
5338
ps aux |grep notification-daemon
earlyoom    1107  0.0  0.0   2612   880 ?        SLs  10:34   0:00 /usr/bin/earlyoom -r 0 -m 60 -s 100 --avoid (^|/)(init|X|sshd|firefox|firefox-bin|dockerd|docker-proxy|gpg-agent|gpg2|whisper|pulseaudio|dwm|monitoring.py|redshift|kbdd|notification-daemon|numlockx|unclutter|autocutsel)$
user        5338  0.0  0.0 262948 24168 ?        Sl   10:34   0:00 /usr/lib/notification-daemon/notification-daemon
user      224915  0.0  0.0   6476  2280 pts/5    S+   13:51   0:00 grep --color=always --no-messages notification-daemon

1107 <-- earlyoom

serg002 ★★★
() автор топика
Последнее исправление: serg002 (всего исправлений: 2)
grep notification-daemon /proc/+([[:alnum:]])/comm 2>&1 | grep -v self | cut -d/ -f3 | xargs kill -9

Вообще это ахтунг, что в pgrep нет возможности применять регулярки

Потому что регулярки умеет grep.

Aceler ★★★★★
()

в pgrep нет возможности применять регулярки

чего?

man pgrep

SYNOPSIS
pgrep [options] pattern

OPERANDS
       pattern
              Specifies an Extended Regular Expression for matching against the process
              names or command lines.
futurama ★★★★★
()