Perl多进程程序的编写
2012-02-16 16:56
302 查看
用fork函数实现多进程。
fork()函数的行为是将目前进程复制一份,用于建立子进程。
其返回值,在子线程中是0,在父线程中是子线程号。
通过判断其返回值来控制各进程的行为。
例程:
my @pids;
my $pid = fork();
if (!defined($pid))
{
print ("Fork process failured!\n");
exit();
}
if ($pid == 0)
{
push @pids, $pid;
print ("This is a child process.\n");
}
else
{
foreach (@pids) {
waitpid($_,0); # 等待子线程
}
print ("This is the parent process. All child processes have finished.\n");
}
fork()函数的行为是将目前进程复制一份,用于建立子进程。
其返回值,在子线程中是0,在父线程中是子线程号。
通过判断其返回值来控制各进程的行为。
例程:
my @pids;
my $pid = fork();
if (!defined($pid))
{
print ("Fork process failured!\n");
exit();
}
if ($pid == 0)
{
push @pids, $pid;
print ("This is a child process.\n");
}
else
{
foreach (@pids) {
waitpid($_,0); # 等待子线程
}
print ("This is the parent process. All child processes have finished.\n");
}
相关文章推荐
- 在notepad++中编写perl程序并直接运行
- 编写多进程程序 --多进程编程
- 走向并行系列之-使用ForkManager编写多进程程序
- 用PERL 程序编写一个从ORACLE数据库中取数然后规范格式插入到EXCEL中的程序
- 使用QPM编写PHP 多进程程序
- 使用QPM编写PHP 多进程程序
- [转载]在notepad++中编写perl程序并直接运行
- 一个perl多进程的简单程序框架
- 使用perl编写socket程序范例
- 使用Perl编写CGI程序(前后端)
- 看图学习用D语言编写包含资源的win32 GUI程序
- centos 安装eclipse编写C/C++程序
- linux vi 编写C/java程序
- vc socket 多线程 (记录一次自己调用window 底层API编写 vc socket 多线程的服务器网络程序)
- 编写了一个服务器端的程序实现在客户端输入字符然后在控制台上显示,直到输入"END"为止,让你写出客户端的程序;
- 编写简单的中文分词程序
- IntelliJ IDEA + Maven环境编写第一个hadoop程序
- hadoop如何执行自己编写的MapReduce程序
- 编写一个使用数组类模板Array对数组进行排序、求最大值和求元素和的程序,并采用相关数据进行测试。
- thrift安装以及编写小程序