Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you start a background process in Perl?

Tags:

windows

perl

I'm trying to figure out how to start a background process in a perl script (on Windows). In other words, I don't want the script to wait for the child process to complete before regaining control. Is there an easy way to do this in just a few lines of code? I've looked at perldoc for the system command, but it doesn't seem to do what I want..

like image 903
pepsi Avatar asked Mar 30 '11 01:03

pepsi


People also ask

How do I run a process in the background in Perl?

Either external programs or perl subroutines can be launched and controlled as processes in the background. sub mysleep { sleep(shift); } # Define mysleep() $myproc->start(\&mysleep, 10); # Launch it. $myproc->start(sub { sleep(10); });

How do I run a shell background process?

Use bg to Send Running Commands to the Background You can easily send such commands to the background by hitting the Ctrl + Z keys and then using the bg command. Hitting Ctrl + Z stops the running process, and bg takes it to the background. You can view a list of all background tasks by typing jobs in the terminal.

How do I run an exec in Perl?

exec - Perldoc Browser. The exec function executes a system command and never returns; use system instead of exec if you want it to return. It fails and returns false only if the command does not exist and it is executed directly instead of via your system's command shell (see below).

How do I fork in Perl?

The fork() Function in PerlThe fork() function is used to clone a current process. This call create a new process running the same program at the same point. It returns the child pid to the parent process, 0 to the child process, or under if the fork is unsuccessful.


1 Answers

See system in perlport: "system(1,@args) spawns an external process and immediately returns its process designator, without waiting for it to terminate...(Win32)"

like image 160
ysth Avatar answered Oct 05 '22 04:10

ysth