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

Re: tcp server holding xterm

by zentara (Archbishop)
on Aug 10, 2007 at 18:52 UTC ( [id://631866]=note: print w/replies, xml ) Need Help??


in reply to tcp server holding xterm

There are certain things you need to do with a daemon, to make it a real daemon. Search groups.google.com for "perl daemon" for alot of discussion and sample scripts. There is also a modules to make it easy....Proc::Daemon

Here is the basic idea.

#!/usr/bin/perl use warnings; use strict; use POSIX 'setsid'; use IO::Socket; $|++; my $server = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $server; $server->autoflush(1); daemonize(); open(LOG,">/tmp/7070.log") or die "$\n"; while(1){ while ( my $client = $server->accept() ){ sysread($client, my $buf, 100); syswrite(LOG, "$buf\n"); LOG->flush; } } ################################################################# sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found