AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[ps](unix)

Martin Hope
Mathias Sven
Asked: 2025-03-18 07:41:57 +0800 CST

procps 的 watch 与 ps 命令一起截断命令行

  • 5

设置是,我现在在当前目录下有两个文件夹,busybox-1.36.1和,并且我还有一个正在运行的procps-4.0.4服务。现在观察不同的行为:languagetoolDynamicUser=yes

图例:✅ 不截断;❌ 截断。

busybox 手表 & busybox ps ✅

./busybox-1.36.1/bin/watch './busybox-1.36.1/bin/ps aux | grep languagetool'
Every 2.0s: ./busybox-1.36.1/bin/ps aux | grep languagetool                                                                           2025-03-17 23:20:02

1026972 61534    39:36 java ...languagetool...
4053857 mathiass  0:00 ./busybox-1.36.1/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool
4053882 mathiass  0:00 sh -c -- ./busybox-1.36.1/bin/ps aux | grep languagetool
4053884 mathiass  0:00 grep languagetool

busybox 观看并 procps ps ✅

./busybox-1.36.1/bin/watch './procps-4.0.4/bin/ps aux | grep languagetool'
Every 2.0s: ./procps-4.0.4/bin/ps aux | grep languagetool

languag+ 1026972  0.1 13.6 14468788 4464816 ?    Ssl  Mar04  39:38 java ...languagetool...
mathias+ 4057218  0.0  0.0   4676  2244 pts/32   S+   23:35   0:00 ./busybox-1.36.1/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool
mathias+ 4057222  0.0  0.0 231736  3788 pts/32   S+   23:35   0:00 sh -c -- ./procps-4.0.4/bin/ps aux | grep languagetool
mathias+ 4057224  0.0  0.0 230732  2520 pts/32   S+   23:35   0:00 grep languagetool

procps 观看 & procps ps ❌

./procps-4.0.4/bin/watch './procps-4.0.4/bin/ps aux | grep languagetool'
Every 2.0s: ./procps-4.0.4/bin/ps aux | grep languagetool

mathias+ 4056463  0.0  0.0 230836  3320 pts/32   S+   23:31   0:00 ./procps-4.0.4/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool
mathias+ 4056540  0.0  0.0 230836  1532 pts/32   S+   23:32   0:00 ./procps-4.0.4/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool
mathias+ 4056541  0.0  0.0 231736  3556 pts/32   S+   23:32   0:00 sh -c -- ./procps-4.0.4/bin/ps aux | grep languagetool
mathias+ 4056543  0.0  0.0 230732  2244 pts/32   S+   23:32   0:00 grep languagetool

procps 监视 & busybox ps ✅

./procps-4.0.4/bin/watch './busybox-1.36.1/bin/ps aux | grep languagetool'
Every 2.0s: ./busybox-1.36.1/bin/ps aux | grep languagetool                                                                nixos: Mon Mar 17 23:33:31 2025

1026972 61534    39:38 java ...languagetool...
4056826 mathiass  0:00 ./procps-4.0.4/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool
4056831 mathiass  0:00 ./procps-4.0.4/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool
4056832 mathiass  0:00 sh -c -- ./busybox-1.36.1/bin/ps aux | grep languagetool
4056834 mathiass  0:00 grep languagetool

问题

奇怪的是,在其他所有情况下,命令的行为都符合我的预期,除了尝试同时使用ps和watchfrom 时procps。有人知道这是怎么回事吗?

ps
  • 2 个回答
  • 33 Views
Martin Hope
YoctoDragon
Asked: 2024-05-06 18:44:01 +0800 CST

ps:无效选项--'p'

  • 9

我正在使用 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
  • 1 个回答
  • 256 Views
Martin Hope
lightxy233
Asked: 2023-12-21 15:28:30 +0800 CST

`ps axjf` 和 `ps -axjf` 之间的区别

  • 6

我正在尝试更深入地了解psLinux中的命令。

当我使用时我很困惑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.

尤其是fand-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 命令,但我还没有找到很好的解释。

ps
  • 1 个回答
  • 34 Views
Martin Hope
S. N.
Asked: 2023-04-13 04:04:56 +0800 CST

为什么 ps aux | grep <something> 返回额外命中 [重复]

  • 12
这个问题在这里已经有了答案:
如何防止“grep”出现在 ps 结果中? (17 个答案)
7 天前关闭。

假设我想知道当前正在运行的 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
  • 3 个回答
  • 979 Views
Martin Hope
Saeed Neamati
Asked: 2022-12-05 03:49:13 +0800 CST

如何告诉 ps 为 cmd 使用更多空间?[复制]

  • 5
这个问题在这里已经有了答案:
增加 ps -o 列宽 (2 个答案)
2 天前关闭。

我正在使用此命令查看我的顶级进程:

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
  • 1 个回答
  • 23 Views
Martin Hope
DDS
Asked: 2022-11-29 09:16:15 +0800 CST

相当于“ps -p”

  • 8

我使用的是一块没有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
  • 1 个回答
  • 169 Views
Martin Hope
ShbBB
Asked: 2022-09-23 03:48:02 +0800 CST

如何使用状态 -R 显示进程

  • 0

我正在尝试使用STATfield输出所有进程-R。

我尝试了以下命令,但它不是最佳匹配。有没有其他显示方式??

ps aux |grep  R

输出

text-processing ps
  • 1 个回答
  • 16 Views
Martin Hope
Manuel Jordan
Asked: 2022-06-15 15:55:14 +0800 CST

ps 命令:'-q' 选项如何工作?

  • -4

根据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)

但我不清楚以下部分:

问题

  1. (快速模式)是什么意思?-快点什么?
  2. 使用此选项 ps 仅读取 pidlist 中列出的 pid 的必要信息并且不应用其他过滤规则是什么意思?
  3. The order of pids is unsorted and reserved 是什么意思?-如果理论上我们正在定义明确的 pid 集,为什么是未排序的?我是说ps -q <pid1>,<pid2>,...,<pidN>
  4. 因此带着这三个首要问题:什么时候强制使用这个-q选项?
man ps
  • 1 个回答
  • 52 Views
Martin Hope
Manuel Jordan
Asked: 2022-06-15 07:22:33 +0800 CST

ps 命令:如何显示带有选项、管道和重定向的完整命令?(或全部一起)

  • 0

关于ps命令,为简单起见考虑是否:

  • intty3执行yes命令
  • intty4执行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 options
  • 1 个回答
  • 34 Views
Martin Hope
ChennyStar
Asked: 2022-06-12 01:53:39 +0800 CST

为什么 X 应用程序在 ps 的结果中显示一个问号作为 TTY?

  • 3
$ 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)?

tty ps
  • 2 个回答
  • 135 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve