gpt4 book ai didi

Bash,服务器在杀死 tmux 进程后意外退出

转载 作者:行者123 更新时间:2023-12-04 16:16:28 27 4
gpt4 key购买 nike

我在 bash 中编写了一个脚本来加载自定义 tmux session 。
我注意到因为 windows 有一个名字,我不能再次使用脚本,因为 windows 名称已经存在。与其使用一些随机数作为窗口的名称,或者根本不给它命名,我认为终止进程会更容易。

#!/bin/sh

pkill -f tmux

tmux new-session -s "Tab 1"\; \
split-window -v \; \
split-window -h \; \
split-window -v \;
因此,当我使用脚本时,它会在创建 tmux session 之前终止 tmux 进程。我注意到如果 tmux session 打开,它会关闭它但另一个不会打开。相反,它向我抛出了这条消息。
server exited unexpectedly
所以我必须使用该命令两次才能使其工作。
有没有办法一次性执行脚本杀死当前 session 并打开一个新 session ?谢谢!

最佳答案

我不知道这是否是最好的方法,但是从 man tmux 环顾四周我找到了 tmux detach-client命令:

Detach the current client if bound to a key, the client specified with -t, or all clients currently attached to thesession specified by -s. The -a option kills all but the client given with -t. If -P is given, send SIGHUP to theparent process of the client, typically causing it to exit. With -E, run shell-command to replace the client.


这里有用的是 -E选项。我们可以使用它来终止当前 session 并使用您想要的选项启动一个新 session 。
单行解决方案(如果您在 tmux 中):
tmux detach-client -E "tmux kill-session; tmux new-session -s 'Tab 1'\; split-window -v\; \; split-window -v \; split-window -h"

关于Bash,服务器在杀死 tmux 进程后意外退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67470856/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com