#Bash 的 setsid 命令
setsid [OPTION]... [CMD [ARG]...]
功能
使用新的会话运行程序。
类型
可执行文件(/usr/bin/setsid),属于 util-linux。
参数
OPTION选项:-c,--ctty- 将控制终端设为当前终端-f,--fork- 先创建一个子进程,再让子进程调用setsid(2);setsid命令自身是进程组 leader 时必须使用此选项-w,--wait- 等待CMD执行完毕,以CMD的返回值作为setsid的返回值返回--help- 显示帮助--version- 显示版本
CMD- 要运行的命令ARG- 传递给CMD的参数列表
#示例
$ setsid java -jar minecraft_server.jar nogui & # & 表示后台运行
- 在新的会话中运行
minecraft_server,与控制终端解绑,不会收到终端挂断信号,用户注销后仍可继续运行。
#推荐阅读
#手册
SETSID(1) User Commands SETSID(1)
NAME
setsid - run a program in a new session
SYNOPSIS
setsid [options] program [arguments]
DESCRIPTION
setsid runs a program in a new session. The command calls fork(2) if
already a process group leader. Otherwise, it executes a program in the
current process. This default behavior is possible to override by the
--fork option.
OPTIONS
-c, --ctty
Set the controlling terminal to the current one.
-f, --fork
Always create a new process.
-w, --wait
Wait for the execution of the program to end, and return the exit
status of this program as the exit status of setsid.
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
AUTHORS
Rick Sladkey <jrs@world.std.com>
SEE ALSO
setsid(2)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The setsid command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-10-23 SETSID(1)