3

Possible Duplicate:
How can I disown a running process and associate it to a new screen shell?

The problem is that the process is not a job inside of my active shell (as I've logged in from remote because my X-system has crashed), meaning: I guess disown, nohup, CTRL+Z & bg, screen et al. will not work.

Motivation: I started a long running job inside of a gnome-terminal. I want to detach it from the its parent, as I the X-system has crashed. I fear when I kill the X-system, also the Gnome Desktop + Gnome-Terminal + my precious script will be lost. So I still can login from remote and want to save the script process and restart X. How do I do that?

math
  • 185
  • See e.g. http://serverfault.com/questions/24425/can-i-nohup-screen-an-already-started-process for an answer. – jofel Aug 30 '12 at 13:36
  • Please take a look at similar question at SuperUser http://superuser.com/questions/1674/detach-and-reattach-xterms-across-x-sessions – hostmaster Aug 30 '12 at 18:35
  • @jofel: severfaults answer uses disown, which does not work for jobs outside of your current shell. – math Aug 31 '12 at 13:11
  • @hostmaster: The answer you selected could solve my problem but will only work for X-applications. I want it to work with any application. – math Aug 31 '12 at 13:12
  • @Gilles: Did I said that screen does not work afterwards? – math Aug 31 '12 at 13:13
  • @math No, you wrote “I guess … screen et al. will not work”. I don't know why you guessed that, nor how you intended to use screen. Nonetheless, your situation is the same as that previous question: you have a process running in a terminal and you want to disconnect it from that terminal. Here the terminal is an X terminal emulator (Gnome-terminal) rather than sshd, but this doesn't change the answer. By the way, you should read difference between a 'terminal', a 'shell' … as you seem to be confusing the notions of shell and terminal. – Gilles 'SO- stop being evil' Aug 31 '12 at 13:31
  • @Gilles, convinced, you are right and the second part of your answer you gave in http://unix.stackexchange.com/questions/4034/how-can-i-disown-a-running-process-and-associate-it-to-a-new-screen-shell is really solving my problem. You could mark it as duplicate to this question. – math Aug 31 '12 at 16:17
  • @math I should have mentioned that the 2nd answer on serverfaults about reptyr is what you need. – jofel Aug 31 '12 at 17:17
  • @all and I should have read more carefully. – math Aug 31 '12 at 19:40

1 Answers1

1

Depending on the scripting language you use to run the job you could use

setpgrp()
Perl: setpgrp PID, PGRP

to detach the running process from the controlling terminal, so once it starts the controlling terminal can exit without harming the running process.

Now from what you are describing you will have the controlling terminal and shell by running Gnome Terminal and starting your job from there so nohup should work just fine for you.

Karlson
  • 5,875