为什么 ps -al 不显示我的 java 程序?

为什么 ps -al 不显示我的 java 程序?

我不明白为什么ps -alsudo ps -al不会显示例如我的 java 进程。如果我这样做,ps -al那么我看不到例如我的 java 作业,但是当我执行(奇怪且无法识别)时我可以看到它们,ps -xal | grep java这可能应该是别的。我还可以通过 netstat 找到 java(jetty 服务器)正在运行的端口(端口 80)的 java PID,获取端口 80 上进程的 PID,然后通过其 PID 将其终止。我似乎并不总是sudo killall java有效。您能否帮助我制定一个可行的策略,以简化处理 2-3 个 jetty 实例的运行,这些实例有时只会在执行时出现ps -al?我想最好的方法是以类似于启动 ie 的方式停止 jetty,sudo mvn jetty:stop但 jetty 手册说只需终止进程就可以了,这样更快。(我经常想重新启动 jetty。)

答案1

  • -ax是进程选择器,因此ps将显示过滤后的进程列表。

    如果要查看全部流程使用:ps axps -axps -A,甚至a-a都不一样。参考:man ps

    SIMPLE PROCESS SELECTION
           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.  Identical to -e.
    
           -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.
    
  • 要杀死它,请尝试使用sudo killall -s9 ...。参考:终止命令和信号

相关内容