我正在使用 Yocto Project (honister) 来构建我的操作系统映像。当我尝试使用 vscode ssh 扩展时,出现错误:
> ps: invalid option -- 'p'
> BusyBox v1.34.1 () multi-call binary.Usage: ps
> Exec server process not found
有任何想法吗?我可以安装什么?还有其他 ps 实现吗?
我正在使用 Yocto Project (honister) 来构建我的操作系统映像。当我尝试使用 vscode ssh 扩展时,出现错误:
> ps: invalid option -- 'p'
> BusyBox v1.34.1 () multi-call binary.Usage: ps
> Exec server process not found
有任何想法吗?我可以安装什么?还有其他 ps 实现吗?
我正在尝试更深入地了解ps
Linux中的命令。
当我使用时我很困惑ps axjf
,ps -axjf
当我发现它们在手册中似乎有不同的含义但它们的输出几乎相同时。
它们之间的具体区别是什么?
对于这些选项,手册说:
a Lift the BSD-style "only yourself" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes when used together with the x option.
-a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
x Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.
j BSD job control format.
-j Jobs format.
f ASCII art process hierarchy (forest).
-f Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c option, the format keyword args, and the format keyword comm.
尤其是f
and-f
选项,似乎-f
没有输出层次关系的意义。
我比较了这两个命令的输出,除了几行之外,它们几乎相同。
lightxy233@iZ8vb0rgcfh3yx60rzee1jZ:~$ ls
_axjf.txt axjf.txt
lightxy233@iZ8vb0rgcfh3yx60rzee1jZ:~$ diff _axjf.txt axjf.txt
81c81
< 2 639305 0 0 ? -1 I 0 0:00 \_ [kworker/u4:0-flush-252:0]
---
> 2 639305 0 0 ? -1 I 0 0:00 \_ [kworker/u4:0-events_unbound]
126,127c126,127
< 630827 630830 630830 630830 pts/0 641497 Ss 1000 0:00 | \_ -bash
< 630830 641497 641497 630830 pts/0 641497 R+ 1000 0:00 | | \_ ps axjf
---
> 630827 630830 630830 630830 pts/0 641448 Ss 1000 0:00 | \_ -bash
> 630830 641448 641448 630830 pts/0 641448 R+ 1000 0:00 | | \_ ps -axjf
129c129
< 630845 641496 630845 630845 ? -1 S 1000 0:00 | \_ sleep 1
---
> 630845 641447 630845 630845 ? -1 S 1000 0:00 | \_ sleep 1
我认为这可能涉及混合不同风格的 ps 命令,但我还没有找到很好的解释。
假设我想知道当前正在运行的 kate 编辑器的 PID(kate 只是一个例子,它的工作原理与许多程序的描述一样)。所以,我执行ps aux | grep kate
.
这是输出:
seifert 35523 0.0 0.2 448724 25144 ? Sl 08:56 0:33 /bin/kate -b
seifert 1499179 0.0 0.0 12196 656 pts/0 S+ 21:52 0:00 grep --color=auto kate
第一行是我期望看到的。但是第二个是什么?
我正在使用此命令查看我的顶级进程:
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
但是,它的 CMD 列切断了路径。例如我看到这个结果:
PID PPID CMD %MEM %CPU
583875 583874 node /Company/Projects/A 7.4 6.2
1597 1594 node /Company/Projects/A 7.4 0.3
585721 585720 node /Company/Projects/A 6.5 3.4
2549 2548 node /Company/Projects/A 6.1 0.1
51143 51142 node /Company/Projects/A 5.1 0.0
210960 210959 node /Company/Projects/A 4.3 0.0
40609 40608 node /Company/Projects/A 4.0 0.0
2188 2187 node /Company/Projects/A 3.3 0.0
42198 42197 node /Company/Projects/A 3.1 0.0
我无法区分进程。
如何增加该CMD
列的长度?
我使用的是一块没有ps
安装完整命令的板。我需要的是ps -p
等效的(设置$?
是否找到特定 PID 的东西)。
有没有办法用另一个命令(比如top)来完成这个?
## wannabe_watchdog.sh
MY_EXE="$1"
_pid=-1
while test 1 -eq 1
do
## this ps -p isn't available on the busybox
ps -p ${_pid}
if test $? -eq 0
then
echo "executing"
sleep 10
else
echo "not executing"
./${MY_EXE} &
sleep 1
agent_pid=$(cat /var/run/my_pidfile.pid)
echo "waiting for ${_pid}"
#wait function sometimes isn't blocking (and I never figured out exactly when)
wait ${_pid}
echo "${_pid} is dead - restarting"
fi
done
根据ps
命令,对于-q
选项
通过man
表示:
-q pidlist
Select by PID (quick mode). This selects the processes whose process ID numbers appear
in pidlist. With this option ps reads the necessary info only for the pids listed in
the pidlist and doesn't apply additional filtering rules. The order of pids is
unsorted and preserved. No additional selection options, sorting and forest type
listings are allowed in this mode. Identical to q and --quick-pid.
并通过ps --help a
-q, q, --quick-pid <PID>
process id (quick mode)
但我不清楚以下部分:
问题
ps -q <pid1>,<pid2>,...,<pidN>
-q
选项?关于ps
命令,为简单起见考虑是否:
tty3
执行yes
命令tty4
执行yes > /dev/null
命令通过ps
我需要在报告中显示带有选项、管道和重定向的完整命令,在这种情况下重定向,已尝试ps aux
并且ps -ef
没有按预期出现,因为这两种情况总是出现yes
- 我需要查看yes
和 yes > /dev/null
... COMMAND
yes
yes > /dev/null
所以目前这 > /dev/null
部分不包括在内。如何实现这个目标?
关于带有管道的命令mvn clean ... | tee ...
和关于选项的命令tar -xzf /path/to/filename.tar.gz
... COMMAND
mvn clean ... | tee ...
tar -xzf /path/to/filename.tar.gz
或全部:选项、管道和重定向
$ ps -ef | head -n 1 && ps -ef | grep calc
UID PID PPID C STIME TTY TIME CMD
user1 524014 5382 0 10:21 ? 00:00:01 gnome-calculator
user1 532125 510665 0 10:36 pts/4 00:00:00 grep calc
我以为只有守护进程才有?
TTY,但显然 Gnome Calculator 不是守护进程。我知道它在 TTY2 上运行,这是我的 Gnome 会话使用的 TTY。那么为什么ps
结果会显示?
在 TTY 列中呢?
[编辑]
我知道 Gnome Calculator 没有直接附加到 TTY,因为它是通过图形外壳(Gnome Shell)启动的。我认为通过上升进程树,我会得到一个附加到 TTY2 的进程,但事实并非如此:
$ ps -f | head -n 1 && ps -ef | grep calc
UID PID PPID C STIME TTY TIME CMD
user1 524014 5382 0 10:21 ? 00:00:01 gnome-calculator
user1 578611 552619 0 11:58 pts/5 00:00:00 grep calc
$ ps -f -p 5382
UID PID PPID C STIME TTY TIME CMD
user1 5382 5131 4 juin10 ? 00:42:26 /usr/bin/gnome-shell
$ ps -f -p 5131
UID PID PPID C STIME TTY TIME CMD
user1 5131 1 0 juin10 ? 00:00:00 /lib/systemd/systemd --user
$ echo $DISPLAY
:1
TTY2 没有任何上游进程连接到 TTY2。但显然 Gnome Calculator 当前显示在 TTY2 上。是否有命令找出给定进程当前显示在哪个 TTY 上?(或者可能在哪个$DISPLAY
)?
是否可以使用命令列出所有正在运行的后台进程ps
,或者是获取后台进程列表的唯一选项jobs
?