13

如果我使用ps -efW,它会列出 Windows 进程,但不会使用命令行参数。

我遇到了三个链接,我被告知要使用pstree/proc/PID/cmdlineprocps

http://cygwin.com/ml/cygwin/2007-04/msg00813.html

http://cygwin.com/ml/cygwin/2007-04/msg00817.html

http://cygwin.com/ml/cygwin/2007-04/msg00821.html

procps但是,除了Cygwin 32 位软件包之外,我没有找到任何东西。

即使我安装了procps它,我也不知道如何使用它。我阅读了手册页,但没有得到任何线索。

有人可以帮忙吗?

例如,使用wmic命令,我可以看到带有参数的完整过程。

C:\Users\test1>wmic process get ProcessID, Commandline /format:csv |grep cmd
OSWIN7VC10-32B1,"C:\Windows\system32\cmd.exe" ,2904
OSWIN7VC10-32B1,C:\Windows\system32\cmd.exe /c c:\ostore74\src\osci\scripts\buil
d_test\nt\batch_conf\winnt_vc100_weekly.bat >C:\Users\test1\AppData\Local\Tem
p\s1io.4 2>C:\Users\test1\AppData\Local\Temp\s1io.5,3968
OSWIN7VC10-32B1,C:\Windows\system32\cmd.exe /c C:\apache-ant-1.7.1\bin\ant.bat -
Djboss.home=C:\ostore74\tmp\javaee\jboss-4.2.3.GA -emacs -k -f C:\ostore74\src\j
mtl\build.xml overnight >> \\ostorenas\odi\ostore_platform_logs\ostore\7.4
.0\test1\winnt_vc100\2013-10-18-1720\unit_retail_jmtl.log 2>&1,1864
OSWIN7VC10-32B1,"C:\Windows\system32\cmd.exe" ,604
OSWIN7VC10-32B1,grep  cmd,2064

但是,使用 Cygwinps命令。

C:\Users\test1>ps -efW |grep cmd
       0    2904       0 ?          Oct 17 C:\Windows\System32\cmd.exe
       0    3968       0 ?          Oct 18 C:\Windows\System32\cmd.exe
       0    1864       0 ?          Oct 18 C:\Windows\System32\cmd.exe
       0    3200       0 ?        08:39:43 C:\Windows\System32\cmd.exe
4

3 回答 3

13

如果您只需要 cygwin 进程的参数,您可以使用

procps -wwFAH

或者

pstree -a

pstree是 psmisc 包的一部分)。

如果您需要 Windows 进程的参数,也可以使用wmic。它在 Cygwin shell 中工作。或者,您可以尝试修补win7util 软件包以包含完整的命令行process.c

于 2014-04-10T16:03:44.287 回答
3

“pgrep -a”也可以解决问题。例如:

$ emacs-w32.exe somefile.txt &

$ pgrep -a emacs
21564 emacs-w32 somefile.txt

$ pgrep -a .   #to see all processes 
于 2018-05-08T11:32:30.713 回答
2

前言:好的……所以这真的很烦人。似乎没有任何可行的方式以编程方式将这些信息抓取到 Cygwin 中。每当我开始一个解决方案时,都需要 20 多分钟,忽略路径/解决方案并将其搁置。使用 WMI、Wmic,甚至从注册表中提取,都变得荒谬。没有提供可靠的信息,而且大多数时候甚至 WMI 都没有列出 CMD 行。总是最终构建了一个 dll/exe 分析器。

然后今天我正在做一些 DLL 工作,不管 Cygwin 是什么,并输入“listdlls”。起初我以为它只是一些滚动函数或别名,很可能是 Nirsoft 的RegDLLView。但很快意识到它可能是 Sysinternal 的listdlls.exe,也就是命令行!

解决方案:

  • 查找并存储可执行名称搜索词的 pid
  • 存储“listdlls.exe”的结果
  • 循环遍历pids数组\
  • 查找 pid 进程名称 \
  • 根据 listdlls 结果打印进程名称的匹配命令行

举个粗略的例子(dependencies = listdlls.exe, grep, awk, ps "procps"):

__getexecmd () {
    [ -z "$@" ] && return 1
    local term="$@"
    hash listdlls || return 1
    local dlls="$(listdlls)"
    for i in $(ps -Wa | awk '/'"$term"'/ {print $1}'); do
        echo "$dlls" | grep -A1 "$i" | awk '/Command\ line\:/{gsub(/Command\ line\:\ /,"");print $0}'
    done
    return 0
}

我真的认为这就是你所追求的。让我知道。干杯

于 2015-02-28T19:13:06.673 回答