Questions tagged [pgrep]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
96 views

Why was pidof and pgrep removed from OpenSuse 15.5?

In openSuse leap 15.5, there are no packages offering pidof? SysVinit-tools package were part of the OS bundle previosuly, but was removed in 15.5. So, is there any alternates without installing ...
Jagan's user avatar
  • 1
2 votes
1 answer
40 views

Why does "pgrep -O 600" fail in an LXC? procps bug?

Debian 12.2 in an unpriviledged LXC (proxmox). It's almost 11:45 AM local time. At 5:00 AM in the morning, cron started a script: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME ...
Jan's user avatar
  • 7,772
0 votes
0 answers
36 views

pgrep returns correct results only for partial script name [duplicate]

I have a script called synchronize_dirs.sh which just wraps a call to sleep: -bash-4.2$ cat synchronize_dirs.sh #!/bin/bash sleep 60 -bash-4.2$ What's confusing to me is the behavior of pgrep in the ...
Pacopenguin's user avatar
-2 votes
1 answer
347 views

How to find one of multiple processes with the same name using pgrep (or another tool)? [closed]

I have several bash scripts running. The only thing that differs between them is the pid. I want to write a script like this that only monitors one specific bash process and exclude any daughter ...
d-b's user avatar
  • 1,901
1 vote
0 answers
75 views

Why does pgrep return randomly a wrong pid? [duplicate]

In the past I used pid-files to guarantee race-condition safe execution of scripts. But this had the downside, that the pid-file was not deleted if the kernel killed the script somehow. So sometimes ...
mgutt's user avatar
  • 467
0 votes
2 answers
202 views

How to use 'pgrep' from a script, when the checked process includes a '-c' (that 'pgrep' considers an argument)? [duplicate]

The following script demonstrates my problem, which is to determine if the sox_user_auditd_v2r -c process is running: $ cat ./pgrep_stackexchange_sample.bash #!/bin/bash -xv quoted="\'$@\'" ...
boardrider's user avatar
1 vote
1 answer
106 views

How to prevent 'pgrep' to consider the expression it checks as containing arguments for it?

I have the following script; it is supposed to start a process if it is not running: $ cat keepalive_stackexchange_sample.bash #!/bin/bash -xv # This script checks if a process is running and starts ...
boardrider's user avatar
2 votes
3 answers
196 views

Find all Processes Except These Specific Ones

Is there a ps or pgrep option or standard practice what will let me list all the running processes on a machine EXCEPT for a few specific ones I don't want to see? Put another way -- let's say I have ...
Alana Storm's user avatar
  • 1,453
2 votes
1 answer
176 views

$(pgrep -f) behaviour changes within a script depending on the shebang

When I run the following script: #!/bin/bash $(pgrep -u ubuntu -f ${1} > /dev/null) echo "CURRENT_STATUS="${?} with: ./my_script.sh top when top is not running, it returns: ...
ozpac's user avatar
  • 33
0 votes
1 answer
189 views

Why does pgrep not find systemd-resolved?

#!/usr/bin/env bash echo "pgrep not finding systemd-resolved has bitten many times." if [ -z $(pgrep systemd-resolved) ]; then echo -e "systemd-resolved not found by pgrep, trying ...
rjt's user avatar
  • 377
2 votes
2 answers
992 views

Autokey - Focus App Window If Running, Launch App If Not

I'm trying to obtain the processID of pcmanfm like this: pgrep -f "pcmanfm" When pcmanfm is not running, the command above returns nothing (as I expect). However, when I run the command ...
Lonnie Best's user avatar
  • 5,123
0 votes
1 answer
3k views

how to use pgrep to find a shell script process

I want to use pgrep command to terminate the running process in centos terminal. I tried: pgrep fedora-proxy-k8s-postgresql | xargs -r kill -9 and I could not found the process because it's a bash ...
Dolphin's user avatar
  • 609
1 vote
1 answer
753 views

Don't understand why pgrep doesn't work in a bash script with sudo

I'm trying to detect whether the zoom program is running. I also need sudo privileges in my bash script to install it with dpkg. If I use pgrep -f "zoom" >/dev/null 2>&1, the ...
Dean's user avatar
  • 424
1 vote
0 answers
234 views

Why pgrep hangs when clang AddressSanitizer library is preloaded using LD_PRELOAD?

I noticed that when I set LD_PRELOAD env. variable to libclang_rt.asan-x86_64.so pgrep hangs. Why is this happening and how to avoid this? senx:/$ time pgrep anything real 0m0,022s user 0m0,...
senx's user avatar
  • 171
2 votes
0 answers
355 views

Why is pgrep/pkill so much slower than ps? [closed]

I would have thought that pgrep would be much faster than ps -ef yet the contrary is true - pgrep takes about 4x longer. But only on my laptop e.g.: $ time { ps -ef |grep foobar; } real 0m0.027s ...
wef's user avatar
  • 472
0 votes
1 answer
239 views

IF statment for checking if arecord is working inside a shell script no responding well

I wrote a script that should check if the arecord command line audio recorder is not working, and if so it should start it. With the help of cron, I want to verify that I'm recording within a specific ...
Asaf Chertkoff's user avatar
1 vote
1 answer
963 views

How to get a list of process ids of long command names, not command line parameters?

Since there's a 15-character limit on the length of process names in pgrep, I've been using pgrep -f to give me a list of process id's of running commands with longer names. However, it includes the ...
NewtownGuy's user avatar
1 vote
1 answer
356 views

how to write a pgrep pattern that (never) matches a zero byte?

I'd like to kill a process with a long name that ends with foo. Currently my plan is to use pkill (though for testing, to be friendly to the process, I've been checking my patterns with pgrep instead)....
Daniel Wagner's user avatar
6 votes
2 answers
2k views

Why doesn't "pgrep firefox" work on Ubuntu 20.04

As the title suggests, the following command on Ubuntu 20.04: pgrep firefox ... returns no results. Meanwhile, the following command: ps aux |grep firefox ... returns 6 results, 5 of which should ...
tresf's user avatar
  • 313
3 votes
2 answers
2k views

pgrep -f exits with 1

RUNNING_APPS=$(pgrep -f "somePattern") echo $? #results in 1 How can I make my command pass with exit code 0?
makozaki's user avatar
  • 133
0 votes
1 answer
278 views

Suspicious pgrep run as root user on debian bullseye

I experience quite a bit of fan activity on my laptop, even the machine should be idle. When I take a look at my processes with top I have a pgrep process appear once in a while, taking some CPU. It ...
nath's user avatar
  • 5,694
2 votes
1 answer
324 views

Trying to optimize CPU usage, 'pgrep -x spotify' running despite never installing spotify

I recently installed Arch Linux on a very old laptop. As such, I am trying to optimize it as much as possible and cut down on CPU/RAM usage. Attached is a screenshot I took of htop on the laptop ...
Henry Shackleton's user avatar
-2 votes
1 answer
4k views

What are the differences between pgrep and `ps aux | grep`?

Why is pgrep needed? If we can use ps and grep together, why do we need pgrep? It'd be weird if we have a command lsgrep or curlgrep. But one difference I noticed was, if we first start a tmux ...
nonopolarity's user avatar
  • 3,069
2 votes
1 answer
3k views

How to get pkill to output process information of killed process?

How to get pkill to output process information of killed process? I don't see anything in man pkill that suggests this is possible. I know I can do a pgrep and process the list and then pipe that to ...
Elijah Lynn's user avatar
  • 1,045
3 votes
0 answers
300 views

pgrep -f matches on first 4096 characters only

pgrep on a Ubuntu 19.10 matches on a cmd line of about 10000 characters just fine, but the same version (see below) of pgrep on Debian 10 (buster) greps only on the first 4096 characters. Is there a ...
Evgeniy Berezovsky's user avatar
5 votes
2 answers
6k views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
Tube's user avatar
  • 51
1 vote
1 answer
1k views

Cron watchdog for a python script

I have a python script that should be restarted automatically every time it fails. I've trying to use for this purpose cron with the following setting: */2 * * * * pgrep -f handler.py || /usr/bin/...
Viktor Zaionchkovskyi's user avatar
1 vote
1 answer
2k views

pgrep returns different results if run from script than if run in terminal

I have written a script to check how many instances of a process are running in an OpenWrt based system. If I run the following in my terminal COUNT_PS=$(echo `ps -w | grep -v grep | grep upmpdcli | ...
dmSherazi's user avatar
  • 247
0 votes
1 answer
746 views

Getting different results running same commands step by step at a terminal and within a script [duplicate]

pid=$(pgrep 'engrampa') #Get the PID of the engrampa processes . killpid=$(echo $pid | head -1) #Get only the first line of the $pid variable and put into a new variable called $killpid. kill $killpid ...
Lucas Rizzini's user avatar
3 votes
1 answer
2k views

Cron job won't run (pgrep issue)

I'm running a cron job every minute, which launches a bash shell script: # Automatically reboot the server if it goes down * * * * * /root/auto-restart.sh I can manually run the script, but whenever ...
johndoe's user avatar
  • 31
3 votes
3 answers
5k views

Does `ps` provide the working directory of each process?

Is it correct that the output of jobs contains the working directory when invoking each job (not necessarily the current working directory of each job)? $ jobs -l | grep JDBC [15] 20422 Running ...
Tim's user avatar
  • 102k
7 votes
1 answer
5k views

How do I check with a Bash script if an application is running?

I have a gnome-run application in my home folder. I have now added the application to run when I press Meta+R (I added it in in CCSM). I run the application by executing ./gnome-run in my home folder. ...
richie's user avatar
  • 205