構文 |
|
wait |
返り値 |
|
終了した子プロセスのプロセスID |
説明
- 子プロセスの終了を待って,終了した子プロセスのプロセスIDを返します。子プロセスが存在しない場合は-1を返します。
- 子プロセスのステータス・コードは$?に格納されます。
使用例
#!/usr/bin/perl
use strict;
use warnings;
if (my $pid = fork()) {
# 親プロセスの処理
my $cpid = wait(); # 子プロセスの終了を待つ
print "child process process id ($cpid)\n";
print "child process status code ($?)\n";
} elsif (defined $pid) {
# 子プロセスの処理
exec 'netstat -n';
} else {
print "Error:$!\n";
}
print "End.\n";
#!/usr/bin/perl
use strict;
use warnings;
my @command = ('netstat', '-n');
my $ret = system @command;
if ($ret != 0) {
print "code[$ret]\n";
}