找到了困难的方法不同套接字下的启动tmux
会话未列出tmux ls
,因为它只是tmux -L default list-sessions
显示属于default
套接字的会话的快捷方式。 (我在用tmux -L
继承tmux
调用 shell 的环境.)
tmux ls
不显示会话的 PID:
$ tmux -L default ls
1: 1 windows (created Thu Mar 30 09:39:31 2023) (attached)
$ tmux -L lofa ls
0: 1 windows (created Tue Apr 25 15:12:00 2023) (attached)
2: 1 windows (created Tue Apr 25 16:25:38 2023)
我天真地尝试通过开始时间来匹配该过程,尽管我可以推断出哪个会话是哪个会话,因为lofa
s 会话的开始时间确实匹配并且只剩下一个是default
s ,但default
会话的时间明显不同。
$ ps x -o lstart,pid,stat,args f
STARTED PID STAT COMMAND
Tue Apr 25 15:01:27 2023 2387795 S sshd: lynx-dev@pts/4
Tue Apr 25 15:01:27 2023 2387796 Ss \_ -bash
Tue Apr 25 15:01:33 2023 2387820 S \_ bash --rcfile /tmp/nix-shell-2387820-0/rc
Tue Apr 25 16:52:21 2023 2393925 R+ \_ ps x -o lstart,pid,stat,args f
Tue Apr 25 15:00:23 2023 2387609 S sshd: lynx-dev@pts/1
Tue Apr 25 15:00:23 2023 2387610 Ss \_ -bash
Tue Apr 25 15:11:51 2023 2389501 S \_ bash --rcfile /tmp/nix-shell-2389501-0/rc
Tue Apr 25 15:12:00 2023 2391030 S+ \_ tmux -L lofa
Tue Apr 25 14:59:32 2023 2385992 S sshd: lynx-dev@pts/0
Tue Apr 25 14:59:33 2023 2385998 Ss \_ -bash
Tue Apr 25 14:59:41 2023 2386007 S+ \_ bash /tmp/nix-shell-2386007-0/rc
Tue Apr 25 14:59:42 2023 2387528 S+ \_ tmux attach
Tue Apr 25 15:12:00 2023 2391032 Ss tmux -L lofa
Tue Apr 25 15:12:00 2023 2391033 Ss+ \_ -bash
Tue Apr 25 16:25:38 2023 2393553 Ss+ \_ -bash
Tue Jan 24 17:58:29 2023 32710 Ss tmux
Wed Apr 12 12:56:35 2023 1187196 Ss \_ -bash
Wed Apr 12 12:57:28 2023 1187935 S \_ bash --rcfile /run/user/1000/nix-shell-1187935-0/rc
Wed Apr 12 13:00:18 2023 1190971 Sl+ \_ /nix/store/ybmibj2kdfd3m1dq9rl8kcpy23av4c74-vim_configurable-9.0.0609/bin/vim -u /nix/store/7lsixnw74d45g3l6g2nfaqw80fsal5jl-vimrc
Wed Apr 12 13:02:36 2023 1191015 Ss \_ /nix/store/38db4p333ibll7r1v151yc5f6ms1fr00-bash-interactive-5.2-p15/bin/bash
Wed Apr 12 13:02:42 2023 1191725 S+ \_ bash --rcfile /run/user/1000/nix-shell-1191725-0/rc
Tue Jan 24 17:54:53 2023 22116 Ss /lib/systemd/systemd --user
Tue Jan 24 17:54:53 2023 22117 S \_ (sd-pam)
Thu Jan 26 02:42:42 2023 98296 SLs \_ /usr/bin/gpg-agent --supervised
Tue Apr 11 21:08:13 2023 1178866 Ss \_ /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
答案1
tmux list-sessions
接受格式字符串(请参阅“格式”部分在手册页中):
$ tmux ls -F 'socket_path: #{socket_path} | session_name: #{session_name} | server_pid: #{pid} | pane_pid: #{pane_pid}'
socket_path: /tmp/tmux-1000/default | session_name: 1 | server_pid: 32710 | pane_pid: 1187196
$ tmux -L lofa ls -F 'socket_path: #{socket_path} | session_name: #{session_name} | server_pid: #{pid} | pane_pid: #{pane_pid}'
socket_path: /tmp/tmux-1000/lofa | session_name: 0 | server_pid: 2391032 | pane_pid: 2391033
socket_path: /tmp/tmux-1000/lofa | session_name: 2 | server_pid: 2391032 | pane_pid: 2393553
或者使用换行符:
$ tmux -L lofa ls -F \
> 'socket_path: #{socket_path}
> └── session_name: #{session_name} | server_pid: #{pid} | pane_pid: #{pane_pid}'
socket_path: /tmp/tmux-1000/lofa
└── session_name: 0 | server_pid: 2391032 | pane_pid: 2391033
socket_path: /tmp/tmux-1000/lofa
└── session_name: 2 | server_pid: 2391032 | pane_pid: 2393553