in reply to writing to logfile in a loop

On a side note, you could also install a signal handler.
I believe Task Manager just sends a SIGTERM.
You could always catch the signal and then close your handles gracefully.

Replies are listed 'Best First'.
Re^2: writing to logfile in a loop
by ikegami (Patriarch) on Nov 21, 2006 at 23:34 UTC

    I believe Task Manager just sends a SIGTERM.

    There's no such thing as signals in Windows. The closest parallel is the message queues of windows.

    Furthermore, Task Manager's behaviour varies depending on which tab ("Applications" or "Processes") the item being terminated is located.

    When "ending" a "Process", the application is forcibly terminated. ( Reference: TerminateProcess(hProcess, uExitCode) )

    When "ending" an "Application", it sends a WM_QUIT WM_CLOSE message to the window. If the application is still running after a small period of time, the user is told the process is not responding, and he is asked whether he wants to terminate the process or not. If the user chooses to terminate the process, it is forcibly terminated. ( Reference: EndTask(hWnd, FALSE, TRUE) )

      Is Perl capable of handling Windows messaging? I know that if you were writing a Windows app, you could just have a message loop and handle the WM_CLOSE message.
        All Windows can (and must) handle Windows messages. If your Perl app has a window (using Tk, wxPerl, or whatever), then yes. Unfortunately, most Perl scripts don't have a window. (The console doesn't count because Perl doesn't manage that window.)
Re^2: writing to logfile in a loop
by brig (Scribe) on Nov 22, 2006 at 02:26 UTC

    Windows does not use UNIX signals.

    This is a piece of Windows software that sends various kinds of close commands to windows programs. It can send specifics including WM_CLOSE and SC_CLOSE. I believe that TaskManager uses User32.dll->EndTask().

    Check this out, it can kill anything:

    Advanced Process Termination