Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

shut down HTTP::SERVER::SIMPLE

by blueberryCoffee (Scribe)
on Oct 04, 2006 at 05:10 UTC ( #576253=perlquestion: print w/replies, xml ) Need Help??

blueberryCoffee has asked for the wisdom of the Perl Monks concerning the following question:

I have an application that uses HTTP::Server::Simple and I would like to have some way of shutting down the server from within the program. I tried using die but it reported that it died and seemed to keep on running. Anyone know how this can be accomplished?

Thanks

Replies are listed 'Best First'.
Re: shut down HTTP::SERVER::SIMPLE
by MonkE (Hermit) on Oct 04, 2006 at 13:20 UTC
    You didn't say how you were invoking the server (a code sample would be nice), but if you are using the background method, then you'll have to store the $pid it returns so that you can kill the process later with the Perl kill command.

    For example:

    $pid = $HTTP_SERVER->background; # do other stuff ... # when you want to kill it.. kill 9, $pid;
Re: shut down HTTP::SERVER::SIMPLE
by philcrow (Priest) on Oct 04, 2006 at 13:12 UTC
    At least on Linux (and probably other unices) you can signal your own process. Use the kill command:
    kill 2, $$;
    Here $$ is the pid of the current process (the one for the running script). The signal number is the same one you would use with kill at the command line. See man kill for a list or a pointer to the C header which has the list (it's usually called signal.h). I choose 2 (INT), which users get at the command line with CTRL-C. I know HTTP::Server::Simple doesn't trap that, because I have a manual trap for it in one of my scripts.

    The Third Camel says this works differently for Windows, but the Third Camel is a few years old (published in 2000). It claims that on Windows, the kill command causes the process to exit with the signal number as its status (unless the signal is zero, which is not fatal). But that might be just what you want.

    Phil

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://576253]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2023-01-31 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?