如何列出用户拥有的所有进程?

列出我的用户的所有进程名称。

我可以做到

ps aux | grep username 

但输出结果如下:

 maythux 18343 0.0 0.1 1070868 34504 ? Sl Jun03 0:07 empathy maythux 21562 0.0 0.1 703716 32104 ? Sl Jun10 0:00 /usr/bin/python /usr/bin/blueman-applet maythux 21574 0.0 0.0 53532 2408 ? S Jun10 0:00 /usr/bin/obex-data-server --no-daemon maythux 25197 0.0 1.0 2199840 258576 ? Sl May27 0:24 remmina 

但我只想让输出看起来像:

 empathy blueman-applet obex-data-serve remmina 

那么最简单的方法是什么?

你可以轻松地使用ps本身,而无需任何其他工具:

 ps -U user-name -o comm= 

如果你想要一些排序和删除重复条目的王者,你可以这样做:

 ps -U user-name -o comm= | sort | uniq 

这是我输出的示例:

 liferea mission-control nacl_helper nautilus nm-applet notify-osd nxclient.bin nxnode.bin obex-data-serve okular polkit-gnome-au 

为了完成,您还可以使用pgrep

 pgrep -lU foobar 

这将匹配用户foobar真实用户ID。 这将显示带有PID的输出。

如果只需要进程名称,还要删除重复项:

 pgrep -lU foobar | cut -d' ' -f2 | sort -u ##Using RUID pgrep -lu foobar | cut -d' ' -f2 | sort -u ##Using EUID