Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何以编程方式使用命令运行多个屏幕?_Linux_Shell_Gnu Screen - Fatal编程技术网

Linux 如何以编程方式使用命令运行多个屏幕?

Linux 如何以编程方式使用命令运行多个屏幕?,linux,shell,gnu-screen,Linux,Shell,Gnu Screen,我是linux屏幕工具的新手,现在我必须创建很多屏幕,并向每个屏幕传递一些命令。如何以编程方式实现这一点,而不是使用Ctrl+a c创建每个屏幕并在屏幕上键入命令?使用tmux,tmux具有更现代的API,并且在大多数情况下易于使用。要使用tmux实现您的目标,您需要: $ tmux new-session -s foo -d # create a new session called foo $ tmux new-window -t foo

我是linux屏幕工具的新手,现在我必须创建很多屏幕,并向每个屏幕传递一些命令。如何以编程方式实现这一点,而不是使用Ctrl+a c创建每个屏幕并在屏幕上键入命令?

使用tmux,tmux具有更现代的API,并且在大多数情况下易于使用。要使用tmux实现您的目标,您需要:

$ tmux new-session -s foo -d                # create a new session called foo
$ tmux new-window -t foo                    # create a new window
$ tmux send-keys -t foo.0 ./your_script.sh  # window number starts with 0
$ tmux new-window -t foo                    # another new window
$ tmux send-keys -t foo.1 ./another_command # another of your script
...
$ tmux attach -t foo                        # attach to your session, escape key is ^b

为什么要这样做?因为我正在多核机器上并行一些进程,所以每个屏幕都会运行一个带有特定参数的命令,该参数会随着每个屏幕的变化而变化。为什么不使用nohup或在后台使用&?运行作业呢?