Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I'm not sure why pidof doesn’t work, but pgrep works.
$ pidof squid
returns nothing
$ pgrep squid
returns 3322
How can I get the 3322 using pidof?
pidof will return details regarding the name of a actual program whereas pgrep will return details regarding any processes that match the provided pattern. This is clearly stated in the man pages of both tools.
pidof [-s] [-c] [-n] [-x] [-m] [-o omitpid[,omitpid..]] [-o omitpid[,omitpid..]..] program [program..]
vs.
pgrep [options] pattern
When you're looking for the executable squid, pgrep can match it because the pattern matches /usr/bin/squid*. Whereas pidof cannot find a program called squid, because the Squid daemon is likely called something like /usr/bin/squid-server.
For example, here I'm looking at the output of ps and looking for programs running with the name systemd within them:
$ ps -eaf | grep systemd
root 1 0 0 Sep03 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 425 1 0 Sep03 ? 00:00:03 /usr/lib/systemd/systemd-journald
root 480 1 0 Sep03 ? 00:00:00 /usr/lib/systemd/systemd-udevd
dbus 630 1 0 Sep03 ? 00:00:01 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 648 1 0 Sep03 ? 00:00:00 /usr/lib/systemd/systemd-logind
pgrep is able to find them as well:
$ pgrep -l systemd
1 systemd
425 systemd-journal
480 systemd-udevd
648 systemd-logind
But pidof only finds the first one:
$ pidof systemd
1
That's because the PID 1, has the name /usr/bin/systemd.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 months ago.
Improve this question
when I use docker run -itd mysql,then to use ps -elf check the process infomation with "4 S systemd+ 257584 257561 1 80 0 - 712611 poll_s Jul17 ? 00:40:16 mysqld".
root#xx:/proc/257584/ns# ps -elf | grep mysqld
4 S systemd+ 257584 257561 1 80 0 - 712611 poll_s Jul17 ? 00:40:20 mysqld
root#xx:/proc/257584/ns# ps -el | grep mysqld
4 S 999 257584 257561 1 80 0 - 712611 poll_s ? 00:40:21 mysqld
But I use "cat /cat/passwd" can't find username equal to "systemd+".
docker Version: 20.10.12
os ubuntu20.04
ps (sadly) trims the username to 8 (if i'm counting right) characters and adds a + after the user name initial part. The username could be systemd-mysql or systemd-something that you can find in passwd.
From manual:
If the length of the username is greater than the length of the display column, the username will be truncated. See the -o and -O formatting options to customize length
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I was trying to find out, how do i get the pid, process name, command line of the current terminal(what is running in the background and got started with that terminal)?
By running:
echo $$
15925
You will get the process ID of your current session. Using this process ID, you can then run:
ps -ef | grep 15925
foo 14870 15925 0 10:32 pts/6 00:00:00 sleep 120
foo 14871 15925 0 10:32 pts/6 00:00:00 ps -ef
foo 14872 15925 0 10:32 pts/6 00:00:00 grep --color=auto 15925
foo 15925 15919 0 Nov23 pts/6 00:00:08 -bash
The second column will show the parent process (15925) and the second the parent
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have the following process:
root 18538 1 0 00:03 ? 00:00:36 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
root 18541 1 0 00:03 ? 00:00:32 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
root 18544 1 0 00:03 ? 00:00:36 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
root 18545 1 0 00:03 ? 00:00:37 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
root 18546 1 0 00:03 ? 00:00:36 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
root 18547 1 0 00:03 ? 00:00:40 /data/software/anaconda2/envs/py3/bin/python /data/software/anaconda2/envs/py3/bin/gunicorn zapier2cloud.wsgi:application -c ./zapier2cloud.conf.py
I ran the command: sudo pkill -f gunicorn, but after that, it still shows the same processes with the same pids.
What happened? is there any thing wrong?
Sometimes processes can just ignored your kill command. Default signal sent is SIGTERM, if it is not caught, your process will continue to run.
To force kill your process, send a SIGKILL signal using '-9' :
kill -9 {PID}
List of signals :
kill -l
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
First of all, Here is my environment of system:
# cat /proc/version
Linux version 4.15.0-52-generic (buildd#lgw01-amd64-051) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #56-Ubuntu SMP Tue Jun 4 22:49:08 UTC 2019
# cat /etc/issue
Ubuntu 18.04.2 LTS \n \l
Refer to this Ubuntu Wiki, ubuntu has used Systemd by default since 15.04 and Systemd runs with PID 1 as /sbin/init. However, I found the different result on my ubuntu 18.04:
# ps aux | awk '$2==1{print $0}'
root 1 0.0 0.8 159692 8784 ? Ss Oct24 0:21 /sbin/init noibrs splash
# lsof -p 1 | grep txt
systemd 1 root txt REG 252,1 1595792 927033 /lib/systemd/systemd
So, my question is that:
Why Ubuntu 18.04 use /sbin/init instead of /lib/systemd/systemd?
Why lsof -p 1 | grep txt return /lib/systemd/systemd while the process of PID 1 is /sbin/init?
/sbin/init is a symbolic link to /lib/systemd/systemd
Take a look at the output of stat /sbin/init or readlink /sbin/init
This is what they mean by systemd "running as /sbin/init". The systemd binary is linked as /sbin/init and started by that link name.
Update
To further explain the difference between the ps and lsof output: ps is showing the command that started the process, while lsof is showing which files a process has opened.
When systemd was started, it was called by /sbin/init noibrs splash, the file system resolved the link to the file /lib/systemd/systemd which was then read from disk and executed.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
When I use (ps -f&) to display the process information, I found that its PPID is 1, I am confused, why is it not the PID of the main shell (-bash)? I continued to execute the same command twice, and produced a strange process ([bash] <defunct>) with the following output:
The first test:
[root#localhost ~]# (ps -f&)
UID PID PPID C STIME TTY TIME CMD
root 2078 2076 0 01:44 pts/0 00:00:00 -bash
root 2244 1 0 03:07 pts/0 00:00:00 ps -f
The second test:
[root#localhost ~]# (ps -f&)
UID PID PPID C STIME TTY TIME CMD
root 2078 2076 0 01:44 pts/0 00:00:00 -bash
root 2245 2078 0 03:07 pts/0 00:00:00 [bash] <defunct>
root 2246 1 0 03:07 pts/0 00:00:00 ps -f
I tested it many times and found that the [bash] <defunct> process rarely appears (occasionally), but the PPID of the ps -f process is always 1.
My question is:
Why is the PPID of ps -f 1 instead of the PID of the main shell (-bash)?
What is the strange [bash] <defunct> process? Why didn't it appear in the first test?
When you do ( ps -f & ) with the ampersand, the subshell doesn't wait on the ps process so chances are it'll exit sooner than ps. If it does, ps no longer has a parent who'd reap its exit status with wait/waitpid/waitid so what happens on UNIXes is such processes (so called orphan processes) get reparented, normally to the init process (pid == 1) (Linux also allows for the concept of subreapers other than init).
What you're seeing in the second test is a temporary zombie. When a child process exits, it becomes a zombie ([defunct]) until its parent reaps its exit information. You must have caught the subshell at a moment where it exited but its parent (your main shell) hasn't managed to reap its exit info yet. Unless the parent shell is blocked in some way from continuing and thereby reaping the exit info, this should be only a temporary, transient state.