Posted: . At: 10:09 AM. This was 5 years ago. Post ID: 12658
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Get just the PID of a running process.


How to get just the PID of a running process. There are a couple of very useful ways to get the Process ID of a running process.

This is a way using grep and awk. This prints multiple numbers if there are multiple related processes running, like the Apache2 server for example.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ ps axu | grep apache2 | awk '{print $2}'
1570
4555
4556
4557
4558
4559
5900

There is another way to get this information from a process. The pidof command will show the PID of a running process.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ pidof gdm3
1483

Get the name of a running process from the PID easily.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ ps -p 1483 | awk '{print $4}'
CMD
gdm3

Or get more comprehensive information from a process ID with this command.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ ps -f 1483
UID        PID  PPID  C STIME TTY      STAT   TIME CMD
root      1483     1  0 08:39 ?        Ssl    0:00 /usr/sbin/gdm3

This is a very good way to manage processes on your Linux system. Easily get information about a process and return valuable data.

Print the tree of processes run by a certain user. This is quite extensive on the Linux MATE desktop.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ pstree jason
compton
 
gdm-x-session─┬─Xorg───{Xorg}
              ├─mate-session─┬─applet.py───{applet.py}
              │              ├─caja───3*[{caja}]
              │              ├─deja-dup-monito───3*[{deja-dup-monito}]
              │              ├─indicator-appli───2*[{indicator-appli}]
              │              ├─indicator-messa───3*[{indicator-messa}]
              │              ├─indicator-power───3*[{indicator-power}]
              │              ├─indicator-sessi───3*[{indicator-sessi}]
              │              ├─indicator-sound───3*[{indicator-sound}]
              │              ├─mate-maximus───3*[{mate-maximus}]
              │              ├─mate-panel─┬─firefox─┬─2*[Web Content───24*[{Web Content}]]
              │              │            │         ├─Web Content───41*[{Web Content}]
              │              │            │         ├─Web Content───30*[{Web Content}]
              │              │            │         ├─WebExtensions───24*[{WebExtensions}]
              │              │            │         └─64*[{firefox}]
              │              │            └─3*[{mate-panel}]
              │              ├─mate-power-mana───3*[{mate-power-mana}]
              │              ├─mate-settings-d───4*[{mate-settings-d}]
              │              ├─mate-volume-con───2*[{mate-volume-con}]
              │              ├─polkit-mate-aut───2*[{polkit-mate-aut}]
              │              ├─ssh-agent
              │              ├─synapse───14*[{synapse}]
              │              ├─update-notifier───3*[{update-notifier}]
              │              └─3*[{mate-session}]
              └─2*[{gdm-x-session}]
 
gnome-keyring-d───3*[{gnome-keyring-d}]
 
marco───3*[{marco}]
 
pulseaudio───4*[{pulseaudio}]
 
systemd─┬─(sd-pam)
        ├─at-spi-bus-laun─┬─dbus-daemon
        │                 └─3*[{at-spi-bus-laun}]
        ├─at-spi2-registr───2*[{at-spi2-registr}]
        ├─clock-applet───3*[{clock-applet}]
        ├─dbus-daemon
        ├─dconf-service───2*[{dconf-service}]
        ├─gnome-terminal-─┬─bash───pstree
        │                 └─3*[{gnome-terminal-}]
        ├─gvfs-afc-volume───3*[{gvfs-afc-volume}]
        ├─gvfs-goa-volume───2*[{gvfs-goa-volume}]
        ├─gvfs-gphoto2-vo───2*[{gvfs-gphoto2-vo}]
        ├─gvfs-mtp-volume───2*[{gvfs-mtp-volume}]
        ├─gvfs-udisks2-vo───2*[{gvfs-udisks2-vo}]
        ├─gvfsd─┬─gvfsd-trash───2*[{gvfsd-trash}]
        │       └─2*[{gvfsd}]
        ├─gvfsd-fuse───5*[{gvfsd-fuse}]
        ├─gvfsd-metadata───2*[{gvfsd-metadata}]
        ├─mate-screensave───3*[{mate-screensave}]
        ├─mateweather-app─┬─sh───pxgsettings───3*[{pxgsettings}]
        │                 └─3*[{mateweather-app}]
        ├─notification-ar───3*[{notification-ar}]
        ├─trashapplet───2*[{trashapplet}]
        ├─wnck-applet───3*[{wnck-applet}]
        ├─zeitgeist-daemo───2*[{zeitgeist-daemo}]
        └─zeitgeist-fts───2*[{zeitgeist-fts}]

Get information from a process ID that contains the path(s) to logfiles used by that process.

4.4 Fri Nov 02 jason@Yog-Sothoth 0: $ sudo pslog 4555
Pid no 4555:
Log path: /var/log/apache2/error.log
Log path: /var/log/apache2/other_vhosts_access.log
Log path: /var/log/apache2/access.log

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.