Disown scene: we already know that, if the prior in command with nohup or setsid HUP signal can be avoided.
But if we open any processing has already submitted the order, the how to remedy to allow it to avoid the influence of HUP signal?: you want to add nohup or setsid is already too late, can only be achieved through job scheduling and disown to solve this problem. Let's take a look at help: disown disown [-ar] [-h] [jobspec ...] Withoutoptions, eachjobspecisremovedfromthetableoactivejobs.Ifthe-hoptionisgiven, eachjobspecisnotremovedfromthetable, butismarkedsothatSIGHUPisnotsenttothejobiftheshellreceivesaSIGHUP.Ifnojobspecispresent, andneitherthe-anorthe-roptionissupplied, thecurrentjobisused.Ifnojobspecissupplied, te-aoptionmeanstoremoveormarkalljobs; the-roptionwitoutajobspecargumentrestrictsoperationtorunningjobs.Tereturnvalueis0unlessajobspecdoesnotspecifyavalidjob. as can be seen, we can use the following methods to achieve our purpose. Used to make a job disown-hjobspec overlook the HUP signal. Used to make all disown-ah jobs are ignored HUP signal. Used to enable disown-rh running jobs to ignore the HUP signal it should be noted that, when used disown, makes the target jobs from the job list, we will no longer use jobs to view it, but still be able to find it. ps-ef But there's a problem, it is the job of the action object, if we are running a command at the end of the "&" to make it into a job and runs in the background, then all that we can get through jobs command to list all jobs. But if you do not have the current command as a job to run, how to get it working,? the answer is to use CTRL-z (hold down the Ctrl key while you press the z key)! CTRL-z's purpose is to make the current process hangs (Suspend), then we can use jobs command to query its job number, then bgjobspec to put that into the background and continue to run. Note that if a pending affect the results of the current process, using this method. Flexible use CTRL-z in our daily work, we can use to set the current process CTRL-z is suspended to the suspended operation, perform background with some other actions, and then use the fg to pending process back into the foreground (also available in bg to pending process in the background) to continue to run. So that we can in a Terminal run multiple flexible switching tasks, this is especially useful when debugging the code. Because the code editor to hang in the background and then put it back in again, position the cursor still in the position of the last hangs, avoiding the relocation of the trouble. Disown example 1 (if you submit an order with "&" command in the background, you can directly use "disown") root @ pvcent107 build] # cp-rtestLargeFilelargeFile & [1] 4825root @ pvcent107 build] # jobs [1] + Runningcp-i-rtestLargeFilelargeFile & root @ pvcent107 build] # disown-% 1root @ pvcent107 build] # ps-ef | greplargeileroot4825968109: 46pts/4: 00: 00cp-i-rtestLargeFilelargeileroot4853968009: 46pts/4: 00: 00greplargeileroot @ pvcent107 build] # logoutdisown example 2 (if the commit command does not use "&" command in the background, you can use the "bg" CTRL-z and place it into the background, and then use the "disown") root @ pvcent107 build] # cp-rtestLargeFilelargeFile2 [1] + Stoppedcp-i-rtestLargeFilelargeFile2root @ pvcent107 build] # bg% 1 [1] + cp-i-rtestLargeFilelargeFile2 & root @ pvcent107 build] # jobs [1] + Runningcp-i-rtestLargeFilelargeFile2 & root @ pvcent107 build] # disown-% 1root @ pvcent107 build]#ps-ef|greplargeFile2root57905577110:04pts/300:00:00cp-i-rtestLargeFilelargeFile2root58245577010:05pts/300:00:00greplargeFile2root@pvcent107 build]#
No comments:
Post a Comment