我有一个命令,可以使用git将文件从LinuxShell上传到远程服务器,这需要很多小时才能完成.
我怎样才能把正在运行的程序放在后台?这样我就可以继续在shell上工作,这个过程也就完成了?
我有一个命令,可以使用git将文件从LinuxShell上传到远程服务器,这需要很多小时才能完成.
我怎样才能把正在运行的程序放在后台?这样我就可以继续在shell上工作,这个过程也就完成了?
使用CTRL+Z暂停进程,然后使用命令bg
在后台恢复进程.例如:
sleep 60
^Z #Suspend character shown after hitting CTRL+Z
[1]+ Stopped sleep 60 #Message showing stopped process info
bg #Resume current job (last job stopped)
有关作业(job)控制和bg
用法的更多信息,请参见bash
手册页:
JOB CONTROL
Typing the suspend character (typically ^Z, Control-Z) while a process is running causes that process to be stopped and returns control to bash. [...] The user may then manipulate the state of this job, using the bg command to continue it in the background, [...]. A ^Z takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded.bg [jobspec ...]
Resume each suspended job jobspec in the background, as if it had been started with &. If jobspec is not present, the shell's notion of the current job is used.
EDIT
启动一个进程,你甚至可以杀死终端,它仍在运行
nohup [command] [-args] > [filename] 2>&1 &
例如
nohup /home/edheal/myprog -arg1 -arg2 > /home/edheal/output.txt 2>&1 &
要忽略输出(不是很明智),请将文件名更改为/dev/null
要将错误消息设置为其他文件,请将&1
更改为文件名.
此外:您可以使用jobs
命令查看这些后台进程的索引列表.您可以通过运行kill %1
或kill %2
来终止一个后台进程,数字是该进程的索引.