#!/usr/bin/perl use warnings; use strict; use Net::RawIP; use POSIX; daemonize(); while (1) { my $pid = fork(); print "Process number of script is $$\n"; unless (defined ($pid)) { die "Resources unavailable to fork\n"; } elsif ($pid == 0) { my $a = new Net::RawIP; my $p = $a->pcapinit("eth0","udp port 68",1500,30); my $f = ["User-defined message"]; loop $p,10,\&process_pkt,$f; } elsif ($pid) { for (my $i=0; $i <= 10; $i++ ) { sleep 1; print "in parent...$i seconds have elapsed...\n"; } print "killing child process $pid"; kill 9, $pid; sleep 60; } } # end of while loop sub process_pkt { print "packet captured\n"; my $raw_pkt = $_[2]; my $raw_data = unpack "H*", $raw_pkt; print $raw_data,"\n"; } sub daemonize { my $pid = fork(); exit if $pid; setsid(); }