Questions tagged [pgrep]
29 questions
7
votes
1 answer
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.
I can't find any trace of the application…
richie
- 205
- 3
- 6
6
votes
2 answers
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 match pgrep firefox. What's wrong with the…
tresf
- 273
- 2
- 8
5
votes
2 answers
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 uses that... However this just doesn't work, It…
Tube
- 51
- 1
- 2
3
votes
2 answers
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
- 133
- 6
3
votes
0 answers
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 way to make the Debian version match on the whole…
Evgeniy Berezovsky
- 775
- 1
- 7
- 20
3
votes
1 answer
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 I try running it through a cron job it won't run.…
johndoe
- 31
- 3
3
votes
3 answers
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 PDFXCview all.pdf & (wd:…
Tim
- 98,580
- 191
- 570
- 977
2
votes
3 answers
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 four processes running
% ps
PID TTY TIME…
Alana Storm
- 1,413
- 3
- 14
- 17
2
votes
1 answer
$(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:
CURRENT_STATUS=0
which is odd, as I would expect a 1 exit status from…
ozpac
- 33
- 4
2
votes
2 answers
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 from python, it returns a process ID even when pcmanfm is not…
Lonnie Best
- 4,895
- 6
- 27
- 42
2
votes
0 answers
Why is pgrep/pkill so much slower than ps?
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
user 0m0.009s
sys 0m0.023s
Compare with:
$ time…
wef
- 452
- 2
- 6
2
votes
1 answer
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 without much running other than a terminal:
There are…
Henry Shackleton
- 133
- 3
2
votes
1 answer
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 kill but hoping this is in native pkill. I also…
Elijah Lynn
- 965
- 1
- 11
- 19
1
vote
0 answers
Why does pgrep return randomly a wrong pid?
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 manual interaction was needed (remove the pid…
mgutt
- 377
- 2
- 16
1
vote
1 answer
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 it if it's not.
# If the process is already…
boardrider
- 252
- 1
- 12