如何将命令行参数传递给 unix/linux 系统上正在运行的进程?
在 SunOS 上,有 pargs
命令可以打印传递给正在运行的进程的命令行参数。
其他Unix环境下有类似的命令吗?
On SunOS there is pargs
command that prints the command line arguments passed to the running process.
Is there is any similar command on other Unix environments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
有多种选择:
Linux 上的
/proc/
中有更多信息,只需查看即可。在其他 Unix 上情况可能有所不同。
ps
命令在任何地方都适用,/proc
内容是特定于操作系统的。 例如,在 AIX 上,/proc
中没有cmdline
。There are several options:
There is more info in
/proc/<pid>
on Linux, just have a look.On other Unixes things might be different. The
ps
command will work everywhere, the/proc
stuff is OS specific. For example on AIX there is nocmdline
in/proc
.这样就可以解决问题了:
如果没有 xargs,参数之间将没有空格,因为它们已转换为 NUL。
This will do the trick:
Without the xargs, there will be no spaces between the arguments, because they have been converted to NULs.
完整命令行
Linux 和 Linux 的 Unix 系统你可以使用 ps -ef | grep process_name 获取完整的命令行。
在SunOS系统上,如果您想获得完整的命令行,您可以使用
要获得完整的命令行,您需要成为超级用户。
参数列表
将给出传递给进程的参数的详细列表。 它将像这样输出参数数组:
我没有找到任何类似的 Linux 命令,但我会使用以下命令来获得类似的输出:
Full commandline
For Linux & Unix System you can use
ps -ef | grep process_name
to get the full command line.On SunOS systems, if you want to get full command line, you can use
To get the full command line you need to become super user.
List of arguments
will give a detailed list of arguments passed to a process. It will output the array of arguments in like this:
I didn't find any similar command for Linux, but I would use the following command to get similar output:
在 Linux 上,
输出进程
的命令行(包含参数的命令),每个记录均以NUL
字符终止。Bash Shell 示例:
On Linux
outputs the commandline of the process
<pid>
(command including args) each record terminated by aNUL
character.A Bash Shell Example:
您可以将
pgrep
与-f
(完整命令行)和-l
(长描述)一起使用:此方法与任何其他回应:它适用于CygWin,因此您可以使用它来获取完整命令Windows 下运行的任何进程的行(执行为 提升(如果您想要有关任何提升/管理进程的数据)。 在 Windows 上执行此操作的任何其他方法都比较尴尬( 例如)。
此外:在我的测试中,pgrep 方式是唯一可以获取在 CygWin 的 python 中运行的脚本的完整路径的系统。
You can use
pgrep
with-f
(full command line) and-l
(long description):This method has a crucial difference with any of the other responses: it works on CygWin, so you can use it to obtain the full command line of any process running under Windows (execute as elevated if you want data about any elevated/admin process). Any other method for doing this on Windows is more awkward ( for example ).
Furthermore: in my tests, the pgrep way has been the only system that worked to obtain the full path for scripts running inside CygWin's python.
在 Linux 中打印带有空格的
/proc/PID/cmdline
的另一种变体是:这样
cat
打印 NULL 字符 为^@
,然后使用sed
将它们替换为空格;echo
打印换行符。Another variant of printing
/proc/PID/cmdline
with spaces in Linux is:In this way
cat
prints NULL characters as^@
and then you replace them with a space usingsed
;echo
prints a newline.无需使用多个命令来编辑流,只需使用一个 - tr 将一个字符转换为另一个字符:
Rather than using multiple commands to edit the stream, just use one - tr translates one character to another:
ps -eo pid,args
打印 PID 和完整命令行。ps -eo pid,args
prints the PID and the full command line.您可以简单地使用:
You can simply use:
除了上述所有转换文本的方式之外,如果您简单地使用“字符串”,它会默认使输出在单独的行上。 另一个好处是,它还可以防止出现任何可能扰乱终端的字符。
两者都在一个命令中输出:
strings /proc//cmdline /proc//environ
真正的问题是......有没有一种方法可以查看 Linux 中已更改的进程的真实命令行,以便 cmdline 包含更改后的内容文本而不是运行的实际命令。
In addition to all the above ways to convert the text, if you simply use 'strings', it will make the output on separate lines by default. With the added benefit that it may also prevent any chars that may scramble your terminal from appearing.
Both output in one command:
strings /proc//cmdline /proc//environ
The real question is... is there a way to see the real command line of a process in Linux that has been altered so that the cmdline contains the altered text instead of the actual command that was run.
在 Solaris 上,
类似的功能也可以在类 UNIX 系统上使用。
On Solaris
similar can be used on unix like systems.
在 Linux 上,使用 bash,以带引号的参数输出,以便您可以编辑命令并重新运行它
在 Solaris 上,使用 bash(使用 3.2.51(1)-release 测试)且不使用 gnu 用户空间:
Linux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & pargs "${!}" ps -fp "${!}" declare -p tmpargs eval_me=$( printf "argv_recovered=( " IFS=输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${!}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echo printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\n'" that"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\000'输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\002' "need" "quot"输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }输出:
Solaris Bash 示例:
输出:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash 示例(粘贴到终端中) :
输出:
Solaris Bash 示例:
输出:
On Linux, with bash, to output as quoted args so you can edit the command and rerun it
On Solaris, with bash (tested with 3.2.51(1)-release) and without gnu userland:
Linux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & pargs "${!}" ps -fp "${!}" declare -p tmpargs eval_me=$( printf "argv_recovered=( " IFS=Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${!}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echo printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\n'" that"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\000'Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\002' "need" "quot"Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
\t'"ing" ) ## run in background "${argv[@]}" & ## recover into eval string that assigns it to argv_recovered eval_me=$( printf "argv_recovered=( " </proc/"${!}"/cmdline xargs --no-run-if-empty -0 -n1 \ bash -c 'printf "%q " "${1}"' /dev/null printf " )\n" ) ## do eval eval "${eval_me}" ## verify match if [ "$( declare -p argv )" == "$( declare -p argv_recovered | sed 's/argv_recovered/argv/' )" ]; then echo MATCH else echo NO MATCH fi }Output:
Solaris Bash Example:
Output:
\002' tmpargs=( $( pargs "${pid}" \ | /usr/bin/sed -n 's/^argv\[[0-9]\{1,\}\]: //gp' \ | tr '\n' '\002' ) ) for tmparg in "${tmpargs[@]}"; do printf "%q " "$( echo -e "${tmparg}" )" done; echoLinux bash Example (paste in terminal):
Output:
Solaris Bash Example:
Output:
如果您想获得尽可能长的时间(不确定有什么限制),类似于 Solaris 的 pargs,您可以在 Linux 和 Linux 上使用它 操作系统:
If you want to get a long-as-possible (not sure what limits there are), similar to Solaris' pargs, you can use this on Linux & OSX:
在 Linux 终端中尝试 ps -n 。 这将显示:
1.所有进程正在运行,它们的命令行和它们的PID
之后你就会知道要杀死哪个进程
try
ps -n
in a linux terminal. This will show:1.All processes RUNNING, their command line and their PIDs
Afterwards you will know which process to kill