Try DigitalOcean free for up to two months!

Applications 36 – The “ps” Command Part 2 – Process Selection by List

Discussion in 'Installation' started by Jarret W. Buse, Oct 4, 2015.

  1. Jarret W. Buse

    Jarret W. Buse Well-Known Member Staff Writer

    Joined:
    Jul 3, 2013
    Messages:
    292
    Likes Received:
    403
    Applications 36 – The “ps” Command Part 2 – Process Selection by List

    Now that the basic selection options of the “ps” command have been covered, we can look into selecting processes by list. The basic selection options were covered in the article “Applications 35 – The “ps” Command Part 1 – Basic Process Selection”.

    To see the processes which are running on a Linux system, use the “ps” command. Keep in mind that the command only shows the current instance of running processes.

    NOTE: The use of the “top” command can show the active processes in a continuous state as they change.

    The syntax for the “ps” command is “ps [options]”. The options for the process selection by list follows with examples.

    • -123 – Lists process corresponding to the Process ID (PID).

    To see a specific process when a PID is known, simply list the PID after the dash (-). If a message is shown that lists a Process ID, then in a terminal type the command “ps -id#”. For instance, if a PID is given as “4471”, the command would be “ps -4471” as shown in Figure 1.

    Figure 1.jpg
    FIGURE 1

    • 123 – Identical to -123.

    Do note that the option has no dash (-) before the option “id#” as with all BSD-style options. An example command would be “ps 4471”.

    • -C cmdlist – Select by processes' command name.

    If a user needs to see if a specific program is running, they can get a list by process name. For example, to see if the program “shutter” is running, the command would be “ps -C shutter”. If you need to search for multiple processes, separate the names by a comma and no spaces. For example, to search for the processes “shutter” and “Xorg”, the command would be “ps -C shutter,Xorg” as shown in Figure 2.

    Figure 2.jpg
    FIGURE 2

    • -G grplist – Selection is made by the Real Group ID (RGID) or name. The selection is the processes whose real group name or ID is in the grplist list.

    To get a listing of your current User ID (UID) and Group IDs (GIDs), run the “id” command. An example of the “id” command is shown in Figure 3.

    Figure 3.jpg
    FIGURE 3

    The RGID is the Group you are in which is the one your user account is in and not one by using “su”. From Figure 3, my User Account is in the group ADM which has a Group ID of “4”. To see all processes started by the ADM group, use the command “ps -G 4”. The results of the command are shown in Figure 4.

    Figure 4.jpg
    FIGURE 4

    • -g grplist – The option will select by session when the list is completely numeric (session number). Group ID numbers will work only when some group names are also specified.

    The option works best with group names being specified. For example, to see all the processes started by the “adm” group the command would be “ps -g adm”. To see a list of valid Group Names, use the “id” command.

    • --Group grplist – Select by real group ID (RGID) or name as done with the “-G” option.

    See the “-G” option above.

    • --group grplist – Select by effective group ID (EGID) or name. The “-g” option is an alternative to --group.

    See the “-g” option above.

    • p pidlist – Select by process ID.

    Some error messages which appear may include a Process ID (PID). The PID can be used to find the specific process name. For example, to find the process for the PID of 67, use the command “ps p 67”. Do note that the option has no dash (-) before the option “p” as with all BSD-style options.

    • -p pidlist – Select by process ID.

    See the “p” option above.

    • --pid pidlist – Select by process ID.

    See the “p” option above.

    • --ppid pidlist – Selects a list by the parent PID. Displays processes that are children of those listed in pidlist.

    By specifying a PID, a user can see if the process has children processes. Children processes are those which were started by a main, or parent, process. For example, to open LibreOffice Writer and then open three documents, the LibreOffice process has three children processes. Of course, other children processes may exist as well for plug-ins and such.

    • -s sesslist – Select by session ID. This selects the processes with a session ID specified in sesslist.

    Session IDs (SID) is a subject on the Internet which confuses a lot of people since the IDs are not easy to find. Here is a simple way to find the SIDs. Open “htop”, install it if needed (sudo apt-get install htop). Press “F2” for Setup. Under the “Setup” column, select “Columns”. Under “Available Columns” select “Session”, then press “F5” to add the new column and “F10” when done. The left-most column should show the SIDs for each process. Use the SID to determine which process are running in the Session. The process with same PID as the SID is the Session Leader.

    • --sid sesslist – See the “-s” otion above.

    • t ttylist – Select a list by tty in which processes are running. By not specifying a tty the current one is default.

    To see processes running on a specific tty, specify the tty number. For example, to see the process on tty2, use the command “ps -t 2”. The output only shows a few items, so to see all items use the command “ps -e t 2”. Do note that the option has no dash (-) before the option “t” as with all BSD-style options.


    • -t ttylist – See the “t” option above.

    • --tty ttylist – See the “t” option above.

    • U userlist – Select a list by effective user ID (EUID) or name.

    Shows processes started by the specified user or users. The User ID can be found by using the “id” command. For example, to see a listing of processes started by the user “bob”, the command is “ps U bob”. Do note that the option has no dash (-) before the option “U” as with all BSD-style options.

    • -U userlist – See the “U” option above.

    • -u userlist – See the “U” option above.

    • --User userlist – See the “U” option above.

    • --user userlist – See the “U” option above.

    Try the commands out and see how the output may differ. Also, try combining commands together as shown with the “t” option above.
     

    Attached Files:

    Manoj Maracheea likes this.
  2. Manoj Maracheea

    Manoj Maracheea New Member

    Joined:
    Jan 1, 2017
    Messages:
    2
    Likes Received:
    0
    Hello

    Thanks for these tips.
     

Share This Page