寻找 BASH 脚本中 PID 的环境变量

发布于 2024-07-29 01:27:44 字数 170 浏览 6 评论 0原文

有办法做到这一点吗?

我有一个脚本可以导出一些变量并运行一个组件。

我正在寻找进程运行时其中一些变量的实际值。 (这适用于这里,因为我将把这些值合并到另一个脚本/程序中)

变量本身是特定于 PID 的(我对此很陌生,如果这不是很明显。哈哈!)

谢谢!

Any way to do this?

I have a script that exports a few vars and runs a component.

I'm looking to find out the actual values of some of these vars while the process is running. (Which applies here, because I'll be incorporating those values into another script/program)

The vars themselves are PID specific (I'm quite new at this, if that wasn't obvious. Haha!)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

墨落画卷 2024-08-05 01:27:45

您可以查询 /proc/PID/environ 以获取所有定义的环境变量

You can query /proc/PID/environ for all defined envvars

旧人 2024-08-05 01:27:45

我不确定我是否理解你的问题。 但 ...
如果您在 bash 脚本中导出一些环境变量,那么这将位于它正在执行的进程的环境中(这是因为子进程派生了创建它的进程的所有环境变量)。

I don't sure I understand your question. but ...
If you in your bash script export some environment variables, than this will be in the environment of process it is executing (this since child process derives all environment variable of process created it).

享受孤独 2024-08-05 01:27:45

我检查了该进程的环境文件,但奇怪的是,它本身并不包含该进程的所有定义的环境变量。

导出的变量将特定于某个进程,但我并不总是知道它们。 我正在查询哪些环境变量是特定的并为进程声明的,以及它们的值是什么。

I checked the environ file for that process, but oddly, it doesn't contain all the defined env vars for that process in and of itself.

The exported variables will be specific to a process, but I won't always know them. I'm looking to query which env vars are specific and declared for a process, and what their values are.

孤凫 2024-08-05 01:27:45

嗯,如果我理解正确 - 我想我会让脚本响应“kill”信号,以便使用“trap”提取它的运行时信息。 您可以将元数据写入标准输出。

也许在你的脚本中捕获 SIGHUP 并使其写入标准输出?

Hmm, If I understand correctly - I think i would make the script respond to a "kill" signal so as to extract it's runtime information using "trap". You could write the metadata to stdout potentially.

Maybe trap SIGHUP in your script, and make it write to stdout?

不再见 2024-08-05 01:27:45

如果是Linux你可以这样做:

xargs -0 printf '%s\n' < /proc/${pid}/environ

If it's Linux you can do:

xargs -0 printf '%s\n' < /proc/${pid}/environ
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文