我有一个目前占领terminal的过程
]$ command some_argument
我想从terminal退出并回家,但同时我不想杀死这个正在运行的进程。
对于上面的运行过程,我想实现如下所示:
]$ nohup command some_argument >& logfile &
对于大多数用户来说,放弃已经背景化的过程并redirectSTDOUT是不可行的。 这个答案涵盖了这个话题相当不错。
从当前的shell分离进程并不困难:你正在寻找disown 。 从手册:
SIGNALS .... The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to not receive SIGHUP using disown -h. .... SHELL BUILTIN COMMANDS .... disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If jobspec is not present, and neither -a nor -r is supplied, the shell's notion of the current job is used. If the -h option is given, each jobspec is not removed from the ta‐ ble, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a job‐ spec does not specify a valid job.
如果你想更多地了解nohup和disown实际上做什么,你可以看看这个问题。 (免责声明:无耻自我推销)
我知道您目前正在使用基于Linux的操作系统,但为了logging,以及在使用Solaris 10或更新版本的人员在寻找解决scheme时发现此页面的情况下,Solaris nohup实现您正在寻找的内容:
$ command some_argument ... ^Z[1] + Stopped (SIGTSTP) command some_argument $ bg [1] command some_argument& $ jobs -l [1] + 1061 Running command some_argument $ nohup -p 1061 Sending output to nohup.out $ exit
看起来你很接近:
nohup sh custom-script.sh > custom-out.log &
从这里