我有一个命令,可以使用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 %1kill %2来终止一个后台进程,数字是该进程的索引.

Linux相关问答推荐

在Zenity进度窗口上单击取消后如何停止bash脚本

为什么Read()和cin.get()对输出缓冲区的影响不同?

UTF-8输入和使用XGetICValues

在Groff mm中定义页眉不会更改第一页中的页眉

为什么waitpid(2)可以指定非子进程?

如何从核心转储中获取线程名称?

c++进程状态中的+是什么意思

递归/详尽地将点插入字符串

在 Ansible 中使用 JSON 查询过滤数据以从 ansible_fact 中提取数据

如何使用 Bash 将随机数据块写入文件

ftell 在文件描述符上?

如何使用 sed debug调试正则表达式?

如何在 shell 脚本中动态生成新的变量名?

从 Linux shell 将多个文件从一个目录复制到另一个目录

如何将输出从 grep 传送到 cp?

如何在不重新打印的情况下更新终端中的打印消息

如何列出附加到Linux中共享内存段的进程?

如何从任意 pthread_t 获取线程 ID?

在Linux中使用空格设置环境变量

Linux如何确定下一个PID?