Like this? Sorry I couldn't keep it under 80 characters; I'm sureothers can do better:
perl -le 'push@{$h{$_->[2]}},$_->[1]for map[split],`ps -eaf`;@_=@ARGV;push@ARGV,@_=map$_?@$_:(),@h{@_}while@_;print"@ARGV"' 1
Hugo