- Perl 基礎
- Perl - 主頁
- Perl - 簡介
- Perl - 環境
- Perl - 語法概覽
- Perl - 資料型別
- Perl - 變數
- Perl - 標量
- Perl - 陣列
- Perl - 雜湊
- Perl - IF...ELSE
- Perl - 迴圈
- Perl - 運算子
- Perl - 日期 & 時間
- Perl - 子程式
- Perl - 引用
- Perl - 格式
- Perl - 檔案輸入/輸出
- Perl - 目錄
- Perl - 錯誤處理
- Perl - 特殊變數
- Perl - 編碼標準
- Perl - 正則表示式
- Perl - 傳送電子郵件
- Perl 高階
- Perl - 套接字程式設計
- Perl - 面向物件
- Perl - 資料庫訪問
- Perl - CGI 程式設計
- Perl - 包 & 模組
- Perl - 程序管理
- Perl - 嵌入式文件
- Perl - 函式引用
- Perl 有用資源
- Perl - 疑問與解答
- Perl - 快速指南
- Perl - 有用資源
- Perl - 討論
Perl fork 函式
說明
此函式使用 fork( ) 系統呼叫生成一個新程序。程序之間會複製所有的共享套接字或檔案控制代碼。您必須確保等待您的子程序,以防出現“殭屍”程序。
語法
以下為此函式的簡要語法 −
fork
返回值
fork 失敗則此函式返回 undef,成功後返回子程序 ID 給父程序,0 給成功後的子程序。
示例
以下是顯示該函式基本用法的示例程式碼 −
#!/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
perl_function_references.htm
廣告