Hintergrundprozess über SSH-Verbindung starten
-
Hallo
ich möchte einen Prozess auf einem Windows-Sysem mit SSH starten. Die SSH-Verbindungen soll nach dem Start des Prozesses beendet werden, der Prozess (perl-Skript) soll aber weiterlaufen. Ich habe das mit folgendem Programm und der Funktion CreateProcess versucht. In der DOS-Box funktioniert das, auch wenn ich die DOS-Box schließe (DETACHED_PROCESS). Rufe ich das Programm remote über eine SSH-Verbindungen auf, wird das Perl-Skript angestartet und mit der Beendigung der SSH-Session abgebrochen. Ich vermute das durch die Beendigung der SSH-Session die komplette Prozessgruppe terminiert wird.
Ich bin kein Windows-Spezi, unter Unix/Linux funktionert so ein Kontstrukt (mit ein wenig forken). Das habe ich natürlich im Perl-Skript auch versucht - leider ohne Erfolg.
Gibts es unter Windows eine Möglichkeit einen Prozess von seiner Session zu trennen, so dass er bei der Beendigung der Session nicht automatisch abgebrochen wird. Das Setzen von CREATE_NEW_PROCESS_GROUP bewirkt das leider nicht.
(Das Perl-Skript ist kein Dauerläufer, so dass ein Windows-Dienst eigentlich nicht in Frage kommt.)
Wäre sehr froh, wenn jemand dazu eine Idee hätte ...
SSH-Server: WRQ-Reflection 6.1 Build 19
SSH-Client Aufruf: ssh user@host CreateProcess.exevoid _tmain( int argc, _TCHAR* argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; LPTSTR szCmdline=_tcsdup(TEXT("perl.exe test.pl 60")); //LPTSTR szCmdline=_tcsdup(TEXT(argv[1])); signal (SIGINT, SIG_IGN); signal (SIGTERM, SIG_IGN); signal (SIGBREAK, SIG_IGN); signal (SIGABRT, SIG_IGN); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) szCmdline, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS, // Creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); return; } // Wait until child process exits. //WaitForSingleObject( pi.hProcess, INFINITE ); WaitForInputIdle( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); }