Closed jborean93 closed 6 years ago
This is intentional to keep the implementation in line with how it works on Unix. Otherwise, you may use Task Scheduler to achieve background job/process execution.
@manojampalam thanks for the update, we will have to see what our other options are. In regards to keeping things how they work on Unix, I'm not 100% confident as to how it all works but you can easily run a process "outside" of the SSH shell. For example I can run
nohup cmd="echo"; for i in {1..50}; do $cmd "count: $i"; sleep 1;done > stdout.txt &
Once I exit from the SSH session, the process is still running in the background and the SSH tty no longer exists when running who
. I would have thought this would be similar to Windows when running CreateProcess
with the CREATE_BREAKAWAY_FROM_JOB
creation flag on the process.
IMO task scheduler is a massive pain when it comes to things like this as;
Ultimately if that is what we need to do then that's what we need to do but I'm hoping to avoid it if possible :)
@manojampalam Agree 100% with @jborean93 - the job handling is a fine way to deal with cleaning up after a session closes, but processes that explicitly request breakaway should be allowed to do so (ala nohup on POSIX systems).
Thanks for following up and apologies for a misunderstanding of the original ask. Yes, we should allow child processes to break away at their liberty. This will be fixed in the next drop.
Attached a private if you want to try out. ssh-shellhost.zip
Fantastic, I just tried it out locally and it works as you say, it even fixed another issue where we were creating some jobs, looking forward to the release.
Hi!
I am using Win32-OpenSSH and have read this issue searching a solution to the process killing when the ssh connection is closed.
According to the release notes version v7.6.0.0p1-Beta let applications break away from ssh session. I am using version v7.6.1.0p1-Beta 64 bits version but I can not launch processes in background and they don't continue working when the ssh session is closed.
What is the way to achieve this?
Thanks in advance!
@RDCH106, we currently achieve this through some P/Invoke calls in PoweShell and call the CreateProcess Win32 API with a specific flag. This isn't something simple to do and requires a bit of code to achieve but the easiest way I know of to do this in PowerShell is to use WMI. Here is an example script that uses Win32_Process as sets the CREATE_BREAKAWAY_FROM_JOB flag when creating the process
$proc_info = New-CimInstance -CimClass (Get-CimClass -ClassName Win32_ProcessStartup) -Property @{CreateFlags=16777216} -ClientOnly
$arguments = @{CommandLine="cmd.exe"; ProcessStartupInformation=$proc_info}
Invoke-CimMethod -ClassName Win32_Process -Name Create -Arguments $arguments
@jborean93 Thanks for your answer!
I am using OpenSSH-Win64-v7.7.0.0p1-Beta to invoke a BAT file remotely. The BAT file sets some environment variables and then calls START "" someprogram.exe. This used to work just fine in prior releases of SSH. Now, however, START no longer works. Instead the someprogram.exe instance dies as soon as the BAT file exits. Is this a bug, or should I be doing something differently?
@DerekBennett can you please open a new issue and add a reference to this thread?
done
On Thu, Jun 21, 2018 at 12:01 PM Manoj Ampalam notifications@github.com wrote:
@DerekBennett https://github.com/DerekBennett can you please open a new issue and add a reference to this thread?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PowerShell/Win32-OpenSSH/issues/1032#issuecomment-399155760, or mute the thread https://github.com/notifications/unsubscribe-auth/ABz_P9sEOjKl_UPLf2Jm7KIKnFsJ-Xvoks5t-8NugaJpZM4RpQiq .
-- Derek Bennett Derek@TheBennetts.org 1.917.968.8982
"OpenSSH for Windows" version
1.0.0.0
Server OperatingSystem
Windows Server 2016 Standard Evaluation
Still applies to all other hosts as wellClient OperatingSystem N/A (tested on MacOS though)
What is failing The
ssh-shellhost.exe
process that is spawned on an SSH connection does not allow processes to breakaway from the job. This means any process it spawns won't be able to breakaway from the SSH job. This is useful if you want to run a process while not keeping the SSH connection open.As you can see by Process Explorer, the only limit placed on the Job is
Kill on Job Close
Compared to a process that is spawned by WinRM, it contains some more job limits that are mostly configurable by the service. The key one I am looking for is
Breakaway OK
which allows the process to call theCreateProcess
(and derivative) theCREATE_BREAKAWAY_FROM_JOB
creation flag https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx. You can see this based on the cmd.exe process that I spawned on a WinRM processI'm not sure if this is intentional on your part but it would be good to hear your thoughts on this as this is a key feature Ansible uses to achieve async support on the current WinRM connection. If we were to loose this feature, our options are limited and we may need to resort to scheduled tasks which aren't really that easy to manage.
On a side note this is not a "regression" of the 1.0.0.0 release as this has been the case for the past few releases.