Skip to content

Running Processes

Yves Schelpe edited this page Feb 1, 2017 · 15 revisions

Goal: To provide an overview of the running processes on the device including process name and process id.

Linux

xwininfo -tree -root | grep "SomethingToSearchFor"

This will give the opened windows when on linux distro for xWin. This in combination with

  • xprop -id %window id% (sth like 0x600052% | grep _NET_WM_PID | cut -d'=' -f2 | grep -oP "^\K.*" will return the main PID of the application.
  • xwininfo -tree -root | grep -w -o "0x[0-9a-zA-Z]* will give all window ids

Getting names and proces names based on the opened windows

Running it from terminal
bash nameofscriptbelow.sh

Script Code

#!/bin/sh

known_windows=$(xwininfo -tree -root | grep -w -o "0x[0-9a-zA-Z]*")

for windowid in ${known_windows}
do
  #echo "$windowid"
  if ! [ "$windowid" == "0x0" ]; then
    pid=$(xprop -id $windowid | grep _NET_WM_PID | cut -d'=' -f2)
    if ! [ "x$pid" == "x" ]; then
      windowidlength=$(printf "%s" "$windowid" | wc -c)
      if [ $windowidlength -gt 4 ]; then
        title=$(xprop -id $windowid | grep _NET_WM_NAME | cut -d'=' -f2)    
        process=$(ps -waux | grep $pid | grep -v grep | awk '{ print $11 }')
        echo "windowId: $windowid |; processId: $pid |; processName: $process |; windowTitle: $title"
      fi
    fi
  fi
done

Output For each window that gets fetched the script will produce the following output:
windowId: 0x3000001 |; processId: 2033 |; processName: /usr/share/code/code /usr/share/code/code /usr/share/code/code |; windowTitle: "get_namesandprocesses.sh - Documents - Visual Studio Code"

macOS

ps waux | grep -v grep | grep -v "ps waux" | grep -v awk | awk '{ print $11 }'

This will give the running 'commands' on the machine

ps wacux | grep -v grep | grep -v "ps waux" | grep -v awk | awk '{ print $2 " |; " $11 }'

This will onlu print the command (short names) and the process id attached to it

nodejs package node-window-listing

Windows

tasklist /v /fo table

Image Name PID Session Name Session# Mem Usage User Name CPU Time Window Title
string number string number number string string time(*1) string

(*1)time: number:number:number (e.g.: 0:01:56).

tasklist /v /fo list

Same as above, but in a list format.