Reputation: 135
How could I write a program which handle such signals ?
SIGUSR1
- Print the statistic (like the dd
utility does);SIGUSR2
- Print the amount of free memory;SIGINT
- Send USR1
to itself and quit the program.This is what I have and there is no output:
$| = 1;
kill 'USR1';
kill 'USR2';
$SIG{USR1} = {print `dd if=/def/zero of=/dev/null bs=512`};
$SIG{USR2} = {print `free -m`};
$SIG{INT} = {kill 'USR1' => $$; die};
Upvotes: 1
Views: 812
Reputation: 385556
sub
".
use strict;
use warnings;
$| = 1;
$SIG{USR1} = sub { print `dd if=/def/zero of=/dev/null bs=512`; };
$SIG{USR2} = sub { print `free -m`; };
$SIG{INT} = sub { kill USR1 => $$; die "Interrupt"; };
kill USR1 => $$;
kill USR2 => $$;
Also,
print `...`
is a silly way of writing system('...')
.
use strict;
use warnings;
$| = 1;
sub job1 { system('dd if=/def/zero of=/dev/null bs=512'); }
sub job2 { system('free -m'); }
$SIG{USR1} = \&job1;
$SIG{USR2} = \&job2;
$SIG{INT} = sub { job1(); die "Interrupt"; };
kill USR1 => $$;
kill USR2 => $$;
Upvotes: 8