{"id":417,"date":"2013-07-29T05:11:59","date_gmt":"2013-07-29T12:11:59","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=417"},"modified":"2013-07-29T05:14:02","modified_gmt":"2013-07-29T12:14:02","slug":"disown-and-background-a-unix-process","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/disown-and-background-a-unix-process\/","title":{"rendered":"Disown and background a Unix process"},"content":{"rendered":"

Ever run a very large job and regretting not starting it in the excellent screen utility? If you don't have something like reptyr or retty, you can do the following.<\/p>\n

Push the running job into the background using Control-Z and then background it. Then disown that job from the terminal. At least it will keep running. And if you want to kick off another job when the disowned process finish you can run a little script in a new terminal and checking for the disowned job to finish. Running the new script in screen first off course.<\/p>\n

Background and disown process:<\/span><\/p>\n

\r\n# rsync -av \/zfsapp\/u06\/* \/backup\/u06\/\r\nsending incremental file list\r\ntemp01.dbf\r\n^Z\r\n[1]+  Stopped                 rsync -av \/zfsapp\/u06\/* \/backup\/u06\/\r\n\r\n# bg\r\n[1]+ rsync -av \/zfsapp\/u06\/* \/backup\/u06\/ &\r\n\r\n# disown %1\r\n\r\n# ps -ef | grep u06\r\n    root 23903 23902   1 07:05:07 pts\/5       0:01 rsync -av \/zfsapp\/u06\/temp01.dbf\r\n    root 23901  2656   1 07:05:07 pts\/5       0:01 rsync -av \/zfsapp\/u06\/temp01.dbf\r\n    root 23902 23901   0 07:05:07 pts\/5       0:00 rsync -av \/zfsapp\/u06\/temp01.dbf\r\n<\/pre>\n

Check for a process id to finish before starting a new job:<\/span><\/p>\n

\r\n# more cp_u06.sh\r\n#!\/bin\/bash\r\nwhile ps -p 23903 > \/dev\/null;\r\ndo\r\n printf "."\r\n sleep 60;\r\ndone\r\necho\r\necho "last rsync finished starting new"\r\nrsync -av \/zfsapp\/u07\/* \/backup\/u07\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Ever run a very large job and regretting not starting it in the excellent screen utility? If you don’t have<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}