Pidof finds the process id's (pids) of the named programs.
Questions tagged [pidof]
13 questions
10
votes
3 answers
Why pidof and pgrep are behaving differently?
I have a init script in /etc/init.d/myservice for initialize a service like this:
...
start() {
...
daemon /usr/sbin/myservice
...
}
stop() {
...
pgrep myservice
pidof myservice
ps -ef | grep myservice
...
}
And when I try to stop…
Pigueiras
- 203
- 1
- 2
- 6
5
votes
3 answers
How to poll existence of a background script correctly
I have a problem with the following kind of script:
#!/bin/sh
long_running_script.sh &
while [ `pidof long_running_script.sh` ]
do
echo "."
sleep 1
done
The sript will start a new script to background, and it should print dots…
SKi
- 153
- 1
- 5
4
votes
2 answers
Why is pidof not working?
In the output of ps aux, I can see the process just fine:
# ps aux | grep diff
root 7787 28.7 0.0 9368 4516 pts/3 D+ 13:56 20:33 diff -qr mnt/mnt/md/ mnt/mnt2/
root 13130 0.0 0.0 6144 876 pts/4 S+ 15:07 0:00 grep…
Luc
- 3,418
- 3
- 26
- 37
2
votes
1 answer
How do I check for the existence of a process without a failed exit code being returned?
I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have
pids=$(pidof /usr/bin/Xvfb)
if [ ! -n "$pids" ]; then
Xvfb :0 -screen 5 1024x768x8…
Dave
- 2,348
- 21
- 54
- 84
2
votes
1 answer
What could be happening between pidof and kill to cause "no such process"?
I've inherited quite a bit of code and am looking at a cron job that restarts a service once an hour, no other scripts touch this process and this code is ran.
#The name of the process has been scrubbed to protect the guilty
procpid=$( pidof proc…
Peter Turner
- 1,754
- 3
- 20
- 34
2
votes
1 answer
Using `pidof` with `sh -c`
I was wondering why this command line does not print pidof sh:
$ sh -c "var=`pidof sh` ; echo \$var; ps -H"
This one prints 123 as expected
$ sh -c "var=123 ; echo \$var; ps -H"
I am on Ubuntu Linux.
Ankur Agarwal
- 3,108
- 10
- 35
- 52
2
votes
3 answers
Are there any alternatives to pidof? (smaller footprint)
Well, I've just found out that with extensive usage of pidof in very short intervals, the seemingly tiny tool can be a great CPU hog. (Source: top)
On my older machine, it can easily reach 30 percent peaks especially in batch usage, though only for…
syntaxerror
- 2,236
- 2
- 27
- 49
1
vote
0 answers
pidofproc or pidof working from init.d but not from /usr/sbin
I have a Linux service I'm supporting. It offers the usual start and stop commands. The designer created a wrapper command that is meant to control startup and retries of the main function. The wrapper includes a preliminary check to see if it is…
Sinc
- 173
- 7
1
vote
2 answers
Find ProcessID - pidof not working
I need to try and find the ProcessId of a process.
Initially I was doing:
application="/home/user/apps/appName.app"
appPid=$(pidof -x $application)
This worked fine.
However, it now turns out that the applictaion could run from a variety of…
IGGt
- 2,137
- 8
- 28
- 43
1
vote
3 answers
How can I format output of shell command
I combine top and pidof command:
top -p $(pidof )
If pidof return one id top command works. But if pidof more than one ids top command does not work.
pidof returns ids with one space between them like :…
utarid
- 403
- 2
- 6
- 13
0
votes
1 answer
Running pidof in a function
I want to detect whether my script is already running, so I use this:
pidof -o %PPID -x "$0" >/dev/null && echo 'already running!' && exit 1
That works. But I want it in a function:
#!bin/bash
set -eu
set -o pipefail
checkIfRunning() {
pidof -o…
lonix
- 1,639
- 18
- 32
0
votes
0 answers
Command not showing all Java processes
I noticed that the command in my case, is not listing all Java processes. If I run pidof java I get one single pid as a response. On the other hand, if I run ps aux | grep [j]ava I get a three different pids/Java processes. Any ideas on why this…
chromechris
- 315
- 2
- 4
- 11
0
votes
1 answer
Process name 'masked' by /usr/bin/python and /bin/su
I'm trying to use the pidof command to see my script is already running as I only want this executable if the script is not already running, however, it seems the pidof command is not returning the pid of the script using the name which is displayed…
Alan Kavanagh
- 351
- 5
- 17