亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? perlipc.pod

?? ARM上的如果你對(duì)底層感興趣
?? POD
?? 第 1 頁(yè) / 共 4 頁(yè)
字號(hào):
=head1 NAME

perlipc - Perl interprocess communication (signals, fifos, pipes, safe subprocesses, sockets, and semaphores)

=head1 DESCRIPTION

The basic IPC facilities of Perl are built out of the good old Unix
signals, named pipes, pipe opens, the Berkeley socket routines, and SysV
IPC calls.  Each is used in slightly different situations.

=head1 Signals

Perl uses a simple signal handling model: the %SIG hash contains names or
references of user-installed signal handlers.  These handlers will be called
with an argument which is the name of the signal that triggered it.  A
signal may be generated intentionally from a particular keyboard sequence like
control-C or control-Z, sent to you from another process, or
triggered automatically by the kernel when special events transpire, like
a child process exiting, your process running out of stack space, or
hitting file size limit.

For example, to trap an interrupt signal, set up a handler like this.
Do as little as you possibly can in your handler; notice how all we do is
set a global variable and then raise an exception.  That's because on most
systems, libraries are not re-entrant; particularly, memory allocation and
I/O routines are not.  That means that doing nearly I<anything> in your
handler could in theory trigger a memory fault and subsequent core dump.

    sub catch_zap {
	my $signame = shift;
	$shucks++;
	die "Somebody sent me a SIG$signame";
    }
    $SIG{INT} = 'catch_zap';  # could fail in modules
    $SIG{INT} = \&catch_zap;  # best strategy

The names of the signals are the ones listed out by C<kill -l> on your
system, or you can retrieve them from the Config module.  Set up an
@signame list indexed by number to get the name and a %signo table
indexed by name to get the number:

    use Config;
    defined $Config{sig_name} || die "No sigs?";
    foreach $name (split(' ', $Config{sig_name})) {
	$signo{$name} = $i;
	$signame[$i] = $name;
	$i++;
    }

So to check whether signal 17 and SIGALRM were the same, do just this:

    print "signal #17 = $signame[17]\n";
    if ($signo{ALRM}) {
	print "SIGALRM is $signo{ALRM}\n";
    }

You may also choose to assign the strings C<'IGNORE'> or C<'DEFAULT'> as
the handler, in which case Perl will try to discard the signal or do the
default thing.  Some signals can be neither trapped nor ignored, such as
the KILL and STOP (but not the TSTP) signals.  One strategy for
temporarily ignoring signals is to use a local() statement, which will be
automatically restored once your block is exited.  (Remember that local()
values are "inherited" by functions called from within that block.)

    sub precious {
	local $SIG{INT} = 'IGNORE';
	&more_functions;
    }
    sub more_functions {
	# interrupts still ignored, for now...
    }

Sending a signal to a negative process ID means that you send the signal
to the entire Unix process-group.  This code sends a hang-up signal to all
processes in the current process group (and sets $SIG{HUP} to IGNORE so
it doesn't kill itself):

    {
	local $SIG{HUP} = 'IGNORE';
	kill HUP => -$$;
	# snazzy writing of: kill('HUP', -$$)
    }

Another interesting signal to send is signal number zero.  This doesn't
actually affect another process, but instead checks whether it's alive
or has changed its UID.

    unless (kill 0 => $kid_pid) {
	warn "something wicked happened to $kid_pid";
    }

You might also want to employ anonymous functions for simple signal
handlers:

    $SIG{INT} = sub { die "\nOutta here!\n" };

But that will be problematic for the more complicated handlers that need
to reinstall themselves.  Because Perl's signal mechanism is currently
based on the signal(3) function from the C library, you may sometimes be so
misfortunate as to run on systems where that function is "broken", that
is, it behaves in the old unreliable SysV way rather than the newer, more
reasonable BSD and POSIX fashion.  So you'll see defensive people writing
signal handlers like this:

    sub REAPER {
	$waitedpid = wait;
	# loathe sysV: it makes us not only reinstate
	# the handler, but place it after the wait
	$SIG{CHLD} = \&REAPER;
    }
    $SIG{CHLD} = \&REAPER;
    # now do something that forks...

or even the more elaborate:

    use POSIX ":sys_wait_h";
    sub REAPER {
	my $child;
        while ($child = waitpid(-1,WNOHANG)) {
	    $Kid_Status{$child} = $?;
	}
	$SIG{CHLD} = \&REAPER;  # still loathe sysV
    }
    $SIG{CHLD} = \&REAPER;
    # do something that forks...

Signal handling is also used for timeouts in Unix,   While safely
protected within an C<eval{}> block, you set a signal handler to trap
alarm signals and then schedule to have one delivered to you in some
number of seconds.  Then try your blocking operation, clearing the alarm
when it's done but not before you've exited your C<eval{}> block.  If it
goes off, you'll use die() to jump out of the block, much as you might
using longjmp() or throw() in other languages.

Here's an example:

    eval {
        local $SIG{ALRM} = sub { die "alarm clock restart" };
        alarm 10;
        flock(FH, 2);   # blocking write lock
        alarm 0;
    };
    if ($@ and $@ !~ /alarm clock restart/) { die }

For more complex signal handling, you might see the standard POSIX
module.  Lamentably, this is almost entirely undocumented, but
the F<t/lib/posix.t> file from the Perl source distribution has some
examples in it.

=head1 Named Pipes

A named pipe (often referred to as a FIFO) is an old Unix IPC
mechanism for processes communicating on the same machine.  It works
just like a regular, connected anonymous pipes, except that the
processes rendezvous using a filename and don't have to be related.

To create a named pipe, use the Unix command mknod(1) or on some
systems, mkfifo(1).  These may not be in your normal path.

    # system return val is backwards, so && not ||
    #
    $ENV{PATH} .= ":/etc:/usr/etc";
    if  (      system('mknod',  $path, 'p')
	    && system('mkfifo', $path) )
    {
	die "mk{nod,fifo} $path failed";
    }


A fifo is convenient when you want to connect a process to an unrelated
one.  When you open a fifo, the program will block until there's something
on the other end.

For example, let's say you'd like to have your F<.signature> file be a
named pipe that has a Perl program on the other end.  Now every time any
program (like a mailer, news reader, finger program, etc.) tries to read
from that file, the reading program will block and your program will
supply the new signature.  We'll use the pipe-checking file test B<-p>
to find out whether anyone (or anything) has accidentally removed our fifo.

    chdir; # go home
    $FIFO = '.signature';
    $ENV{PATH} .= ":/etc:/usr/games";

    while (1) {
	unless (-p $FIFO) {
	    unlink $FIFO;
	    system('mknod', $FIFO, 'p')
		&& die "can't mknod $FIFO: $!";
	}

	# next line blocks until there's a reader
	open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";
	print FIFO "John Smith (smith\@host.org)\n", `fortune -s`;
	close FIFO;
	sleep 2;    # to avoid dup signals
    }

=head2 WARNING

By installing Perl code to deal with signals, you're exposing yourself
to danger from two things.  First, few system library functions are
re-entrant.  If the signal interrupts while Perl is executing one function
(like malloc(3) or printf(3)), and your signal handler then calls the
same function again, you could get unpredictable behavior--often, a
core dump.  Second, Perl isn't itself re-entrant at the lowest levels.
If the signal interrupts Perl while Perl is changing its own internal
data structures, similarly unpredictable behaviour may result.

There are two things you can do, knowing this: be paranoid or be
pragmatic.  The paranoid approach is to do as little as possible in your
signal handler.  Set an existing integer variable that already has a
value, and return.  This doesn't help you if you're in a slow system call,
which will just restart.  That means you have to C<die> to longjump(3) out
of the handler.  Even this is a little cavalier for the true paranoiac,
who avoids C<die> in a handler because the system I<is> out to get you.
The pragmatic approach is to say ``I know the risks, but prefer the
convenience'', and to do anything you want in your signal handler,
prepared to clean up core dumps now and again.

To forbid signal handlers altogether would bars you from
many interesting programs, including virtually everything in this manpage,
since you could no longer even write SIGCHLD handlers.  Their dodginess
is expected to be addresses in the 5.005 release.


=head1 Using open() for IPC

Perl's basic open() statement can also be used for unidirectional interprocess
communication by either appending or prepending a pipe symbol to the second
argument to open().  Here's how to start something up in a child process you
intend to write to:

    open(SPOOLER, "| cat -v | lpr -h 2>/dev/null")
		    || die "can't fork: $!";
    local $SIG{PIPE} = sub { die "spooler pipe broke" };
    print SPOOLER "stuff\n";
    close SPOOLER || die "bad spool: $! $?";

And here's how to start up a child process you intend to read from:

    open(STATUS, "netstat -an 2>&1 |")
		    || die "can't fork: $!";
    while (<STATUS>) {
	next if /^(tcp|udp)/;
	print;
    }
    close STATUS || die "bad netstat: $! $?";

If one can be sure that a particular program is a Perl script that is
expecting filenames in @ARGV, the clever programmer can write something
like this:

    % program f1 "cmd1|" - f2 "cmd2|" f3 < tmpfile

and irrespective of which shell it's called from, the Perl program will
read from the file F<f1>, the process F<cmd1>, standard input (F<tmpfile>
in this case), the F<f2> file, the F<cmd2> command, and finally the F<f3>
file.  Pretty nifty, eh?

You might notice that you could use backticks for much the
same effect as opening a pipe for reading:

    print grep { !/^(tcp|udp)/ } `netstat -an 2>&1`;
    die "bad netstat" if $?;

While this is true on the surface, it's much more efficient to process the
file one line or record at a time because then you don't have to read the
whole thing into memory at once. It also gives you finer control of the
whole process, letting you to kill off the child process early if you'd
like.

Be careful to check both the open() and the close() return values.  If
you're I<writing> to a pipe, you should also trap SIGPIPE.  Otherwise,
think of what happens when you start up a pipe to a command that doesn't
exist: the open() will in all likelihood succeed (it only reflects the
fork()'s success), but then your output will fail--spectacularly.  Perl
can't know whether the command worked because your command is actually
running in a separate process whose exec() might have failed.  Therefore,
while readers of bogus commands return just a quick end of file, writers
to bogus command will trigger a signal they'd better be prepared to
handle.  Consider:

    open(FH, "|bogus")	or die "can't fork: $!";
    print FH "bang\n"	or die "can't write: $!";
    close FH		or die "can't close: $!";

That won't blow up until the close, and it will blow up with a SIGPIPE.
To catch it, you could use this:

    $SIG{PIPE} = 'IGNORE';
    open(FH, "|bogus")  or die "can't fork: $!";
    print FH "bang\n"   or die "can't write: $!";
    close FH            or die "can't close: status=$?";

=head2 Filehandles

Both the main process and any child processes it forks share the same
STDIN, STDOUT, and STDERR filehandles.  If both processes try to access
them at once, strange things can happen.  You'll certainly want to any
stdio flush output buffers before forking.  You may also want to close
or reopen the filehandles for the child.  You can get around this by
opening your pipe with open(), but on some systems this means that the
child process cannot outlive the parent.

=head2 Background Processes

You can run a command in the background with:

    system("cmd &");

The command's STDOUT and STDERR (and possibly STDIN, depending on your
shell) will be the same as the parent's.  You won't need to catch
SIGCHLD because of the double-fork taking place (see below for more
details).

=head2 Complete Dissociation of Child from Parent

In some cases (starting server processes, for instance) you'll want to
complete dissociate the child process from the parent.    The easiest 
way is to use:

    use POSIX qw(setsid);
    setsid() 		or die "Can't start a new session: $!";

However, you may not be on POSIX.  The following process is reported
to work on most Unixish systems.  Non-Unix users should check their
Your_OS::Process module for other solutions.

=over 4

=item *

Open /dev/tty and use the TIOCNOTTY ioctl on it.  See L<tty(4)>
for details.

=item *

Change directory to /

=item *

Reopen STDIN, STDOUT, and STDERR so they're not connected to the old
tty.

=item *

Background yourself like this:

    fork && exit;

=item *

Ignore hangup signals in case you're running on a shell that doesn't
automatically no-hup you:

    $SIG{HUP} = 'IGNORE';	# or whatever you'd like

=back

=head2 Safe Pipe Opens

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区福利| 久久理论电影网| 在线观看亚洲一区| 色婷婷av一区二区| 91美女在线视频| 色综合久久99| 欧美日韩三级一区二区| 678五月天丁香亚洲综合网| 7777精品伊人久久久大香线蕉的| 欧美日韩一区二区在线观看| 欧美三级中文字幕| 91精品国产综合久久久久久| 日韩亚洲欧美一区二区三区| 日韩免费性生活视频播放| 欧美精品一区二区不卡| 中文字幕欧美国产| 亚洲免费在线播放| 婷婷丁香久久五月婷婷| 蜜臀av一区二区| 国产精品一级黄| a亚洲天堂av| 欧美在线观看视频一区二区三区| 欧美日韩精品久久久| 日韩午夜中文字幕| 国产亚洲精品7777| 亚洲精品日日夜夜| 免费精品视频在线| 成人性生交大片免费| 在线一区二区观看| 7777精品伊人久久久大香线蕉经典版下载 | 韩国v欧美v日本v亚洲v| 国产精品123| 91在线精品一区二区| 欧美曰成人黄网| 日韩免费高清视频| 亚洲欧洲日韩一区二区三区| 亚洲超碰精品一区二区| 国内外精品视频| 91麻豆自制传媒国产之光| 在线91免费看| 亚洲国产电影在线观看| 亚洲综合视频在线| 国内久久婷婷综合| 日本电影欧美片| 精品国产一区二区三区久久久蜜月| 国产免费久久精品| 亚洲一区二区精品视频| 国产在线不卡视频| 精品视频在线免费| 国产精品狼人久久影院观看方式| 亚洲成人你懂的| 成人99免费视频| 日韩视频一区二区| 亚洲美腿欧美偷拍| 国产老女人精品毛片久久| 欧美三级日韩三级| 国产精品情趣视频| 青青国产91久久久久久 | 国产女同互慰高潮91漫画| 亚洲一二三专区| 成人毛片视频在线观看| 91精品在线免费观看| 亚洲免费电影在线| 国产成人午夜精品影院观看视频| 欧美日本国产视频| 亚洲精品五月天| 粉嫩13p一区二区三区| 日本一区二区三区dvd视频在线| 91网上在线视频| 日韩欧美中文字幕一区| 成人欧美一区二区三区视频网页 | 欧美国产欧美综合| 久久精品国产精品亚洲综合| 色哟哟一区二区在线观看| 久久久久久久久久久久电影| 青青青爽久久午夜综合久久午夜| 91久久人澡人人添人人爽欧美| 欧美午夜免费电影| 亚洲国产精品v| 国内精品久久久久影院一蜜桃| 欧美日韩精品免费观看视频| 亚洲精品视频免费观看| www.视频一区| 国产精品私人自拍| 国产成人综合在线| 久久精品人人做人人综合 | av激情成人网| 国产丝袜欧美中文另类| 国内精品伊人久久久久av一坑 | 婷婷中文字幕一区三区| 欧美在线|欧美| 亚洲一区二区三区四区在线观看 | 色网综合在线观看| 国产精品久久久久久久久动漫| 国产麻豆9l精品三级站| 精品毛片乱码1区2区3区| 免费观看在线色综合| 91精品国产色综合久久不卡蜜臀 | 狠狠色丁香九九婷婷综合五月| 4438x成人网最大色成网站| 亚洲综合清纯丝袜自拍| 欧美性色黄大片| 亚洲v精品v日韩v欧美v专区 | 国产精品久久久久久久蜜臀| 国产91对白在线观看九色| 国产日产欧美一区二区三区| 成人午夜私人影院| 国产精品久久久久一区二区三区| 成人app网站| 亚洲另类在线视频| 91色porny| 亚洲gay无套男同| 欧美疯狂性受xxxxx喷水图片| 丝袜诱惑亚洲看片| 日韩精品一区二区三区蜜臀| 国产麻豆成人精品| 国产精品久线观看视频| 91精品91久久久中77777| 亚洲一区二区三区自拍| 日韩一区二区在线观看视频 | 日韩一级片在线播放| 精品写真视频在线观看| 26uuu久久天堂性欧美| 成人久久18免费网站麻豆 | 国产成人午夜精品影院观看视频| 国产精品美女久久久久aⅴ国产馆| av中文字幕不卡| 亚洲高清不卡在线| 欧美成人r级一区二区三区| 成人中文字幕合集| 亚洲一区在线观看免费观看电影高清 | 欧洲中文字幕精品| 日韩av电影免费观看高清完整版| 精品久久久久久综合日本欧美| 国产成人小视频| 亚洲午夜精品17c| 欧美成人激情免费网| av动漫一区二区| 午夜国产不卡在线观看视频| 久久久综合九色合综国产精品| 91婷婷韩国欧美一区二区| 三级不卡在线观看| 中文字幕国产一区二区| 欧美性色aⅴ视频一区日韩精品| 黑人巨大精品欧美一区| 亚洲欧美另类在线| 亚洲成人在线观看视频| 精品粉嫩超白一线天av| 91原创在线视频| 久久精品久久综合| 亚洲乱码中文字幕综合| 久久综合国产精品| 欧美午夜一区二区三区 | 久久久99精品久久| 在线观看视频一区二区欧美日韩| 另类欧美日韩国产在线| 亚洲人成网站影音先锋播放| 51精品视频一区二区三区| eeuss鲁一区二区三区| 美女高潮久久久| 亚洲精品国产精品乱码不99| 久久毛片高清国产| 欧美久久久久久蜜桃| 91在线观看免费视频| 精品亚洲国产成人av制服丝袜| 一区二区三区精品| 中文字幕免费观看一区| 日韩一级成人av| 欧美色电影在线| aaa欧美色吧激情视频| 国产一区中文字幕| 青娱乐精品视频在线| 亚洲一区二区三区四区中文字幕| 欧美激情一区二区| 精品国产精品网麻豆系列| 欧美剧情电影在线观看完整版免费励志电影| 国产高清亚洲一区| 另类小说图片综合网| 午夜欧美2019年伦理| 一区二区成人在线视频| 国产精品三级av在线播放| 久久综合久久综合九色| 7777女厕盗摄久久久| 精品视频在线免费观看| 一本一本大道香蕉久在线精品 | 成人美女在线视频| 国产一区二区三区久久悠悠色av| 日韩高清在线观看| 亚洲韩国一区二区三区| 亚洲欧美另类久久久精品2019| 国产精品丝袜91| 久久久99精品免费观看不卡| 精品欧美一区二区三区精品久久| 666欧美在线视频| 欧美美女激情18p| 欧美探花视频资源| 欧美性三三影院| 欧美三级日本三级少妇99| 在线观看日产精品| 欧美在线一二三|