该函数使用fork()系统调用分叉一个新进程。所有共享Socket或文件句柄在进程之间都是重复的。您必须确保等待孩子,以防止形成"僵尸"进程。
以下是此函数的简单语法-
fork
如果分叉失败,则此函数返回undef;如果分叉失败,则将子进程ID返回给父进程;如果分叉成功,则返回子进程ID。
以下是显示其基本用法的示例代码-
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-fork.html
来源:LearnFk无涯教程网
#!/usr/bin/perl $pid=fork(); if( $pid == 0 ) { print "This is child process\n"; print "Child process is existing\n"; exit 0; } print "This is parent process and child ID is $pid\n"; print "Parent process is existing\n"; exit 0;
执行上述代码后,将产生以下输出-
This is parent process and child ID is 18641 Parent process is existing This is child process Child process is existing
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕