如何将命令行参数传递给 unix/linux 系统上正在运行的进程?

发布于 2024-07-18 02:41:48 字数 89 浏览 9 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

谈情不如逗狗 2024-07-25 02:41:48

有多种选择:

ps -fp <pid>
cat /proc/<pid>/cmdline | sed -e "s/\x00/ /g"; echo

Linux 上的 /proc/ 中有更多信息,只需查看即可。

在其他 Unix 上情况可能有所不同。 ps 命令在任何地方都适用,/proc 内容是特定于操作系统的。 例如,在 AIX 上,/proc 中没有 cmdline

There are several options:

ps -fp <pid>
cat /proc/<pid>/cmdline | sed -e "s/\x00/ /g"; echo

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 no cmdline in /proc.

一杆小烟枪 2024-07-25 02:41:48

这样就可以解决问题了:

xargs -0 < /proc/<pid>/cmdline

如果没有 xargs,参数之间将没有空格,因为它们已转换为 NUL。

This will do the trick:

xargs -0 < /proc/<pid>/cmdline

Without the xargs, there will be no spaces between the arguments, because they have been converted to NULs.

陌伤ぢ 2024-07-25 02:41:48

完整命令行

Linux 和 Linux 的 Unix 系统你可以使用 ps -ef | grep process_name 获取完整的命令行。

在SunOS系统上,如果您想获得完整的命令行,您可以使用

/usr/ucb/ps -auxww | grep -i process_name

要获得完整的命令行,您需要成为超级用户。

参数列表

pargs -a PROCESS_ID

将给出传递给进程的参数的详细列表。 它将像这样输出参数数组:

argv[o]: first argument
argv[1]: second..
argv[*]: and so on..

我没有找到任何类似的 Linux 命令,但我会使用以下命令来获得类似的输出:

tr '\0' '\n' < /proc/<pid>/environ

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

/usr/ucb/ps -auxww | grep -i process_name

To get the full command line you need to become super user.

List of arguments

pargs -a PROCESS_ID

will give a detailed list of arguments passed to a process. It will output the array of arguments in like this:

argv[o]: first argument
argv[1]: second..
argv[*]: and so on..

I didn't find any similar command for Linux, but I would use the following command to get similar output:

tr '\0' '\n' < /proc/<pid>/environ
雨巷深深 2024-07-25 02:41:48

Linux 上,

cat /proc/<pid>/cmdline

输出进程 的命令行(包含参数的命令),每个记录均以 NUL 字符终止。

Bash Shell 示例

$ mapfile -d '' args < /proc/$/cmdline
$ echo "#${#args[@]}:" "${args[@]}"
#1: /bin/bash
$ echo $BASH_VERSION
5.0.17(1)-release

On Linux

cat /proc/<pid>/cmdline

outputs the commandline of the process <pid> (command including args) each record terminated by a NUL character.

A Bash Shell Example:

$ mapfile -d '' args < /proc/$/cmdline
$ echo "#${#args[@]}:" "${args[@]}"
#1: /bin/bash
$ echo $BASH_VERSION
5.0.17(1)-release
千年*琉璃梦 2024-07-25 02:41:48

您可以将 pgrep-f(完整命令行)和 -l(长描述)一起使用:

pgrep -l -f PatternOfProcess

此方法与任何其他回应:它适用于CygWin,因此您可以使用它来获取完整命令Windows 下运行的任何进程的行(执行为 提升(如果您想要有关任何提升/管理进程的数据)。 在 Windows 上执行此操作的任何其他方法都比较尴尬( 例如)。
此外:在我的测试中,pgrep 方式是唯一可以获取在 CygWin 的 python 中运行的脚本的完整路径的系统。

You can use pgrep with -f (full command line) and -l (long description):

pgrep -l -f PatternOfProcess

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.

笑饮青盏花 2024-07-25 02:41:48

在 Linux 中打印带有空格的 /proc/PID/cmdline 的另一种变体是:

cat -v /proc/PID/cmdline | sed 's/\^@/\ /g' && echo

这样 cat 打印 NULL 字符^@,然后使用 sed 将它们替换为空格; echo 打印换行符。

Another variant of printing /proc/PID/cmdline with spaces in Linux is:

cat -v /proc/PID/cmdline | sed 's/\^@/\ /g' && echo

In this way cat prints NULL characters as ^@ and then you replace them with a space using sed; echo prints a newline.

陈年往事 2024-07-25 02:41:48

无需使用多个命令来编辑流,只需使用一个 - tr 将一个字符转换为另一个字符:

tr '\0' ' ' </proc/<pid>/cmdline

Rather than using multiple commands to edit the stream, just use one - tr translates one character to another:

tr '\0' ' ' </proc/<pid>/cmdline
旧梦荧光笔 2024-07-25 02:41:48

ps -eo pid,args 打印 PID 和完整命令行。

ps -eo pid,args prints the PID and the full command line.

々眼睛长脚气 2024-07-25 02:41:48

您可以简单地使用:

ps -o args= -f -p ProcessPid

You can simply use:

ps -o args= -f -p ProcessPid
千里故人稀 2024-07-25 02:41:48

除了上述所有转换文本的方式之外,如果您简单地使用“字符串”,它会默认使输出在单独的行上。 另一个好处是,它还可以防止出现任何可能扰乱终端的字符。

两者都在一个命令中输出:

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.

标点 2024-07-25 02:41:48

在 Solaris 上,

     ps -eo pid,comm

类似的功能也可以在类 UNIX 系统上使用。

On Solaris

     ps -eo pid,comm

similar can be used on unix like systems.

感情洁癖 2024-07-25 02:41:48

在 Linux 上,使用 bash,以带引号的参数输出,以便您可以编辑命令并重新运行它

</proc/"${pid}"/cmdline xargs --no-run-if-empty -0 -n1 \
    bash -c 'printf "%q " "${1}"' /dev/null; echo

在 Solaris 上,使用 bash(使用 3.2.51(1)-release 测试)且不使用 gnu 用户空间:

IFS=

Linux bash 示例(粘贴到终端中) :

{
## setup intial args
argv=( /bin/bash -c '{ /usr/bin/sleep 10; echo; }' /dev/null 'BEGIN {system("sleep 2")}' "this is" \
    "some" "args "

输出:

MATCH

Solaris Bash 示例:

{
## setup intial args
argv=( /bin/bash -c '{ /usr/bin/sleep 10; echo; }' /dev/null 'BEGIN {system("sleep 2")}' "this is" \
    "some" "args "

输出:

MATCH
\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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux bash 示例(粘贴到终端中) :

输出:

Solaris Bash 示例:

输出:

On Linux, with bash, to output as quoted args so you can edit the command and rerun it

</proc/"${pid}"/cmdline xargs --no-run-if-empty -0 -n1 \
    bash -c 'printf "%q " "${1}"' /dev/null; echo

On Solaris, with bash (tested with 3.2.51(1)-release) and without gnu userland:

IFS=

Linux bash Example (paste in terminal):

{
## setup intial args
argv=( /bin/bash -c '{ /usr/bin/sleep 10; echo; }' /dev/null 'BEGIN {system("sleep 2")}' "this is" \
    "some" "args "

Output:

MATCH

Solaris Bash Example:

{
## setup intial args
argv=( /bin/bash -c '{ /usr/bin/sleep 10; echo; }' /dev/null 'BEGIN {system("sleep 2")}' "this is" \
    "some" "args "

Output:

MATCH
\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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

Linux 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; echo

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; echo

Linux 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; echo

Linux bash Example (paste in terminal):

Output:

Solaris Bash Example:

Output:

ペ泪落弦音 2024-07-25 02:41:48

如果您想获得尽可能长的时间(不确定有什么限制),类似于 Solaris 的 pargs,您可以在 Linux 和 Linux 上使用它 操作系统:

ps -ww -o pid,command [-p <pid> ... ]

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:

ps -ww -o pid,command [-p <pid> ... ]
不及他 2024-07-25 02:41:48

在 Linux 终端中尝试 ps -n 。 这将显示:

1.所有进程正在运行,它们的命令行和它们的PID

  1. 程序启动进程。

之后你就会知道要杀死哪个进程

try ps -n in a linux terminal. This will show:

1.All processes RUNNING, their command line and their PIDs

  1. The program intiate the processes.

Afterwards you will know which process to kill

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文