查找PID所属的tmux会话 [英] Find tmux session that a PID belongs to

查看:121
本文介绍了查找PID所属的tmux会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用htop,所以请查看哪些进程占用了大量内存,以便可以杀死它们.我有很多tmux会话和许多类似的过程.如何检查PID在哪个tmux窗格中,以便确定自己正在杀死要杀死的东西?

I am using htop so see what processes are taking up a lot of memory so I can kill them. I have a lot of tmux sessions and lots of similar processes. How can I check which tmux pane a PID is in so I can be sure I am killing stuff I want to kill?

推荐答案

鉴于以下行中的PID是目标pid号:

Given that PID in the below line is the target pid number:

$ tmux list-panes -a -F "#{pane_pid} #{pane_id}" | grep ^PID

以上内容将标识运行PID的窗格.输出将是两个字符串.第一个数字应与PID相同,第二个数字(带有百分号)为"tmux窗格ID".输出示例:

The above will identify the pane where the PID is running. The output will be two strings. The first number should be the same as PID and the second one (with a percent sign) is "tmux pane id". Example output:

2345 %30

现在,您可以使用"tmux窗格ID"杀死该窗格,而无需手动"搜索它:

Now, you can use "tmux pane id" to kill the pane without "manually" searching for it:

$ tmux kill-pane -t %30


要完全回答您的问题,为了找到PID所属的* tmux会话*,可以使用以下命令:


To answer your question completely, in order to find *tmux session* that a PID belongs to, this command can be used:

$ tmux list-panes -a -F "#{pane_pid} #{session_name}" | grep ^PID
# example output: 2345 development

这是另一个可能有用的行":

Here's another possibly useful "line":

$ tmux list-panes -a -F "#{pane_pid} #{session_name}:#{window_index}:#{pane_index}" | grep ^PID
# example output: 2345 development:2:0


可以在FORMATS部分的tmux手册页中查找所有插值字符串(例如#{pane_pid})的描述.


The descriptions for all of the interpolation strings (example #{pane_pid}) can be looked up in tmux man page in the FORMATS section.

这篇关于查找PID所属的tmux会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆