Find tmux session that a PID belongs to

前端 未结 3 1449
眼角桃花
眼角桃花 2021-02-03 10:16

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 p

3条回答
  •  礼貌的吻别
    2021-02-03 10:36

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

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

    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
    

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

    $ tmux kill-pane -t %30
    


    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
    

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

提交回复
热议问题