要从Windows上的Perl CGI脚本分叉后台进程,可以使用以下方法:
Win32::Process
模块:use Win32::Process;
my $pid = Win32::Process::Create(
$ProcessName,
$CommandLine,
$ProcessStartup,
$CreationFlags,
$Environment,
$CurrentDirectory,
$StartupInfo,
$ProcessInfo
);
fork()
函数:use POSIX;
my $pid = fork();
if ($pid == 0) {
# 子进程代码
} elsif ($pid > 0) {
# 父进程代码
} else {
# 错误处理
}
Win32::Daemon
模块:use Win32::Daemon;
my $pid = Win32::Daemon::StartService();
Win32::Job
模块:use Win32::Job;
my $job = Win32::Job->new();
$job->spawn(
$CommandLine,
$ProcessStartup,
$CreationFlags,
$Environment,
$CurrentDirectory,
$StartupInfo,
$ProcessInfo
);
Win32::Process::Background
模块:use Win32::Process::Background;
my $pid = Win32::Process::Background::Start($CommandLine);
Win32::TaskScheduler
模块:use Win32::TaskScheduler;
my $task = Win32::TaskScheduler->new();
$task->set_command_line($CommandLine);
$task->set_working_directory($CurrentDirectory);
$task->set_run_level($RunLevel);
$task->set_flags($Flags);
$task->set_account_information($AccountName, $Password);
$task->set_idle_wait($IdleWait);
$task->set_idle_duration($IdleDuration);
$task->set_idle_stop_on_idle_end($StopOnIdleEnd);
$task->set_idle_restart_on_idle($RestartOnIdle);
$task->set_network_settings($NetworkName, $NetworkId);
$task->set_priority($Priority);
$task->set_max_run_time($MaxRunTime);
$task->set_delete_on_close($DeleteOnClose);
$task->set_allow_start_on_demand($AllowDemandStart);
$task->set_start_when_available($StartWhenAvailable);
$task->set_stop_if_going_on_batteries($StopIfGoingOnBatteries);
$task->set_run_only_if_network_available($RunOnlyIfNetworkAvailable);
$task->set_enabled($Enabled);
$task->set_hidden($Hidden);
$task->set_run_only_if_idle($RunOnlyIfIdle);
$task->set_wake_to_run($WakeToRun);
$task->set_execution_time_limit($ExecutionTimeLimit);
$task->set_run_only_if_docked($RunOnlyIfDocked);
$task->set_storage($Storage);
$task->set_run_level($RunLevel);
$task->set_run_only_if_logged_on($RunOnlyIfLoggedOn);
$task->save();
以上是一些可以从Windows上的Perl CGI脚本分叉后台进程的方法,可以根据具体需求选择合适的方法。
领取专属 10元无门槛券
手把手带您无忧上云