Child pages
  • Process management
Skip to end of metadata
Go to start of metadata

Introduction

This page is for techniques related to Linux processes and their management.

htop

TBC

Killing

Killing a process tree

Find the root PID of the process tree then generate the command required to kill the entire tree by:

(warning) This sometimes generates a list of processes that are not in the tree.  To be safe, use pstree -p <PID> to check.

PID=362
ps xf | awk -v PID=$PID '
    $1 == PID { P = $1; next }
    P && /_/ { P = P " " $1; K=P }
    P && !/_/ { P="" }
    END { print "kill " K }'

TODO: develop another command, based on parsing pstree output?  This looks promising but the regex needs tightening up to only match PIDs:

kill $(pstree -p <PID> | grep --only-matching '[0-9]*'|tac)

A array of PIDs in a process tree can be generated by:

PID=tree_root_PID
pids=($(pstree --show-pids --long $PID | sed -e 's/.*(//' -e 's/)/ /'))

top

TBC

  • No labels