開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、16章(プロセス管理)の16.9(練習問題)4.を解いてみる。
その他参考書籍
16.9(練習問題)4.
コード(BBEdit, Emacs)
sample4.pl
#!/usr/bin/env perl
# use diagnostics;
use strict;
use warnings;
use 5.016;
use utf8;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
sub my_hup_handler {
state $count = 0;
$count += 1;
say "SIGHUP $count";
}
sub my_cont_handler {
state $count = 0;
$count += 1;
say "SIGCONT $count";
}
sub my_int_handler {
say 'SIGINT';
exit;
}
for (qw/hup cont int/) {
$SIG{uc $_} = 'my_' . $_ . '_handler';
}
while (1) {}
入出力結果(Terminal)
$ ./sample4.pl & [1] 56469 $ kill -HUP 56469 $ SIGHUP 1 $ kill -HUP 56469 $ SIGHUP 2 $ kill -CONT 56469 $ SIGCONT 1 $ kill -HUP 56469 $ SIGHUP 3 $ kill -CONT 56469 $ SIGCONT 2 $ kill -INT 56469 $ SIGINT [1]+ Done ./sample4.pl $ ps PID TTY TIME CMD 56400 ttys001 0:00.07 /opt/local/bin/bash --noediting -i
0 コメント:
コメントを投稿