⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlipc.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 5 页
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "PERLIPC 1".TH PERLIPC 1 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"perlipc \- Perl interprocess communication (signals, fifos, pipes, safe subprocesses, sockets, and semaphores).SH "DESCRIPTION".IX Header "DESCRIPTION"The basic \s-1IPC\s0 facilities of Perl are built out of the good old Unixsignals, named pipes, pipe opens, the Berkeley socket routines, and SysV\&\s-1IPC\s0 calls.  Each is used in slightly different situations..SH "Signals".IX Header "Signals"Perl uses a simple signal handling model: the \f(CW%SIG\fR hash contains namesor references of user-installed signal handlers.  These handlers willbe called with an argument which is the name of the signal thattriggered it.  A signal may be generated intentionally from aparticular keyboard sequence like control-C or control-Z, sent to youfrom another process, or triggered automatically by the kernel whenspecial events transpire, like a child process exiting, your processrunning out of stack space, or hitting file size limit..PPFor example, to trap an interrupt signal, set up a handler like this:.PP.Vb 7\&    sub catch_zap {\&        my $signame = shift;\&        $shucks++;\&        die "Somebody sent me a SIG$signame";\&    }\&    $SIG{INT} = \*(Aqcatch_zap\*(Aq;  # could fail in modules\&    $SIG{INT} = \e&catch_zap;  # best strategy.Ve.PPPrior to Perl 5.7.3 it was necessary to do as little as you possiblycould in your handler; notice how all we do is set a global variableand then raise an exception.  That's because on most systems,libraries are not re-entrant; particularly, memory allocation and I/Oroutines are not.  That meant that doing nearly \fIanything\fR in yourhandler could in theory trigger a memory fault and subsequent coredump \- see \*(L"Deferred Signals (Safe Signals)\*(R" below..PPThe names of the signals are the ones listed out by \f(CW\*(C`kill \-l\*(C'\fR on yoursystem, or you can retrieve them from the Config module.  Set up an\&\f(CW@signame\fR list indexed by number to get the name and a \f(CW%signo\fR tableindexed by name to get the number:.PP.Vb 7\&    use Config;\&    defined $Config{sig_name} || die "No sigs?";\&    foreach $name (split(\*(Aq \*(Aq, $Config{sig_name})) {\&        $signo{$name} = $i;\&        $signame[$i] = $name;\&        $i++;\&    }.Ve.PPSo to check whether signal 17 and \s-1SIGALRM\s0 were the same, do just this:.PP.Vb 4\&    print "signal #17 = $signame[17]\en";\&    if ($signo{ALRM}) {\&        print "SIGALRM is $signo{ALRM}\en";\&    }.Ve.PPYou may also choose to assign the strings \f(CW\*(AqIGNORE\*(Aq\fR or \f(CW\*(AqDEFAULT\*(Aq\fR asthe handler, in which case Perl will try to discard the signal or do thedefault thing..PPOn most Unix platforms, the \f(CW\*(C`CHLD\*(C'\fR (sometimes also known as \f(CW\*(C`CLD\*(C'\fR) signalhas special behavior with respect to a value of \f(CW\*(AqIGNORE\*(Aq\fR.Setting \f(CW$SIG{CHLD}\fR to \f(CW\*(AqIGNORE\*(Aq\fR on such a platform has the effect ofnot creating zombie processes when the parent process fails to \f(CW\*(C`wait()\*(C'\fRon its child processes (i.e. child processes are automatically reaped).Calling \f(CW\*(C`wait()\*(C'\fR with \f(CW$SIG{CHLD}\fR set to \f(CW\*(AqIGNORE\*(Aq\fR usually returns\&\f(CW\*(C`\-1\*(C'\fR on such platforms..PPSome signals can be neither trapped nor ignored, such asthe \s-1KILL\s0 and \s-1STOP\s0 (but not the \s-1TSTP\s0) signals.  One strategy fortemporarily ignoring signals is to use a \fIlocal()\fR statement, which will beautomatically restored once your block is exited.  (Remember that \fIlocal()\fRvalues are \*(L"inherited\*(R" by functions called from within that block.).PP.Vb 7\&    sub precious {\&        local $SIG{INT} = \*(AqIGNORE\*(Aq;\&        &more_functions;\&    }\&    sub more_functions {\&        # interrupts still ignored, for now...\&    }.Ve.PPSending a signal to a negative process \s-1ID\s0 means that you send the signalto the entire Unix process-group.  This code sends a hang-up signal to allprocesses in the current process group (and sets \f(CW$SIG\fR{\s-1HUP\s0} to \s-1IGNORE\s0 soit doesn't kill itself):.PP.Vb 5\&    {\&        local $SIG{HUP} = \*(AqIGNORE\*(Aq;\&        kill HUP => \-$$;\&        # snazzy writing of: kill(\*(AqHUP\*(Aq, \-$$)\&    }.Ve.PPAnother interesting signal to send is signal number zero.  This doesn'tactually affect a child process, but instead checks whether it's aliveor has changed its \s-1UID\s0..PP.Vb 3\&    unless (kill 0 => $kid_pid) {\&        warn "something wicked happened to $kid_pid";\&    }.Ve.PPWhen directed at a process whose \s-1UID\s0 is not identical to thatof the sending process, signal number zero may fail becauseyou lack permission to send the signal, even though the process is alive.You may be able to determine the cause of failure using \f(CW\*(C`%!\*(C'\fR..PP.Vb 3\&    unless (kill 0 => $pid or $!{EPERM}) {\&        warn "$pid looks dead";\&    }.Ve.PPYou might also want to employ anonymous functions for simple signalhandlers:.PP.Vb 1\&    $SIG{INT} = sub { die "\enOutta here!\en" };.Ve.PPBut that will be problematic for the more complicated handlers that needto reinstall themselves.  Because Perl's signal mechanism is currentlybased on the \fIsignal\fR\|(3) function from the C library, you may sometimes be sounfortunate as to run on systems where that function is \*(L"broken\*(R", thatis, it behaves in the old unreliable SysV way rather than the newer, morereasonable \s-1BSD\s0 and \s-1POSIX\s0 fashion.  So you'll see defensive people writingsignal handlers like this:.PP.Vb 8\&    sub REAPER {\&        $waitedpid = wait;\&        # loathe sysV: it makes us not only reinstate\&        # the handler, but place it after the wait\&        $SIG{CHLD} = \e&REAPER;\&    }\&    $SIG{CHLD} = \e&REAPER;\&    # now do something that forks....Ve.PPor better still:.PP.Vb 10\&    use POSIX ":sys_wait_h";\&    sub REAPER {\&        my $child;\&        # If a second child dies while in the signal handler caused by the\&        # first death, we won\*(Aqt get another signal. So must loop here else\&        # we will leave the unreaped child as a zombie. And the next time\&        # two children die we get another zombie. And so on.\&        while (($child = waitpid(\-1,WNOHANG)) > 0) {\&            $Kid_Status{$child} = $?;\&        }\&        $SIG{CHLD} = \e&REAPER;  # still loathe sysV\&    }\&    $SIG{CHLD} = \e&REAPER;\&    # do something that forks....Ve.PPSignal handling is also used for timeouts in Unix,   While safelyprotected within an \f(CW\*(C`eval{}\*(C'\fR block, you set a signal handler to trapalarm signals and then schedule to have one delivered to you in somenumber of seconds.  Then try your blocking operation, clearing the alarmwhen it's done but not before you've exited your \f(CW\*(C`eval{}\*(C'\fR block.  If itgoes off, you'll use \fIdie()\fR to jump out of the block, much as you mightusing \fIlongjmp()\fR or \fIthrow()\fR in other languages..PPHere's an example:.PP.Vb 7\&    eval {\&        local $SIG{ALRM} = sub { die "alarm clock restart" };\&        alarm 10;\&        flock(FH, 2);   # blocking write lock\&        alarm 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -