Take the 2-minute tour ×

Here's what I want to do: I want to get a tree-formatted list of processes from ps (as when you do ps auxwwf), but only of processes that are either owned by me, or are ancestors of processes owned by me. So if I own a bash process way down the tree, and it has ancestors owned by root, I want to see those root ancestors in addition to the ones I own. I do not want to see any process trees that do not contain any processes owned by me.

Is there any way to do this with ps's normal options, or do I need to write a script to parse the output?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

This won't be very fast, but it seems to do the trick:

# Bash, GNU ps
pidchain ()
    if [[ -z $1 ]]; then
    if (( $1 == 0 )); then
        echo "$1";
        pidchain $(ps -p $1 o ppid=);

pids () {
    ps o pid= -u $1 |
        while read pid
            pidchain $pid
        done |
            sort -nu

ps uxwwf -p $(pids username)
share|improve this answer
Close enough; this inspired me to write my own (faster ;-)) version in PHP. –  dirtside Sep 24 '10 at 21:19
@dirtside: Would you post your code as an answer? I actually looked at the source of pstree as a potential starting point (and probably would need to look at pgrep as well), but that project will have to take a number and wait in line. –  Dennis Williamson Sep 24 '10 at 21:23
add comment

Try ps -ejH that displays a tree of processes, based of father-sons links.


To see only your processes

  ps -fjH -u myname
share|improve this answer
That shows processes the OP wants excluded. –  Dennis Williamson Sep 23 '10 at 23:00
Updated the answer –  ring0 Sep 23 '10 at 23:29
That omits processes the OP wants shown. –  Dennis Williamson Sep 24 '10 at 2:30
add comment

This depends on your os, but based on the ps command you gave I think this might work:

ps --user dirtside -uxxf

share|improve this answer
That doesn't show processes the OP wants included. –  Dennis Williamson Sep 23 '10 at 23:01
add comment

Your Answer


