Page 1 of 1

Detach process from putty

Posted: Mon Jul 13, 2009 12:20 pm
by alex.barylski
I have seen how this is done under Linux by appending a & after the command but I'm using Putty under Windows and I need to detach from the Linux process (PHP script) currently running. This script will need to remain running for several hours and I need to go home before that.

Ctrl+D sounds like the solution but it also sounds like it might stop the script as well. :P

EDIT | It seems the '&' would have worked under Windows too but unfortunately the script is already running via normal invocation so can I change the process while it's running the close the putty window?

Anyone?

Re: Detach process from putty

Posted: Mon Jul 13, 2009 3:26 pm
by VladSun
Simply fork() a child process :) It will be detached from the current tty.

http://us3.php.net/manual/en/function.pcntl-fork.php

Re: Detach process from putty

Posted: Mon Jul 13, 2009 3:31 pm
by Darhazer
I don't know about PuTTY, but in the linux shell, if you started a process and later decided to detach yourself, just press Ctrl+Z. Then you can control with bg, fg and jobs the program execution.

Detaching with & usually means, that if you close the terminal, the program will be also closed (it's a child process). So forking will be necessary.

Re: Detach process from putty

Posted: Mon Jul 13, 2009 3:41 pm
by VladSun
And don't forget to redirect STDERR and STDOUT in both (Darhazer's and mine) suggestions.

Re: Detach process from putty

Posted: Tue Jul 14, 2009 8:02 am
by alex.barylski
How do I fork a process while using putty?

Re: Detach process from putty

Posted: Tue Jul 14, 2009 9:39 am
by VladSun
I need to detach from the Linux process (PHP script) currently running.
It really doesn't matter what SSH client you use ;)
Did you look at the pcntl_fork() man page?

Re: Detach process from putty

Posted: Tue Jul 14, 2009 3:23 pm
by alex.barylski
Did you look at the pcntl_fork() man page?
I have not, but I will thanks :)

Re: Detach process from putty

Posted: Tue Jul 14, 2009 6:24 pm
by Weirdan
VladSun wrote:Simply fork() a child process :)
Or even more simply run the script via nohup.

Re: Detach process from putty

Posted: Wed Jul 15, 2009 3:15 am
by VladSun
Yes, I should admit that my approach is more for daemonizing processes (i.e. daemons ;) ) and not for "simple" background run.

Re: Detach process from putty

Posted: Wed Jul 15, 2009 4:40 pm
by Darhazer
Weirdan wrote:
VladSun wrote:Simply fork() a child process :)
Or even more simply run the script via nohup.
Great tip, 10x