One: System
The system function is the simplest way to start a Perl subroutine. Eg:system "Date"
1: Can use Shell function to start background process
System "Run_cmd with Parameters &"; #在后台执行
2:system performs a normal return value of 0, otherwise the return value is not 0.
3: Multiple parameters supported
Two: exec function
similar to system;
Difference: The system creates a child process to execute external commands, the parent process waits for the created child process to end and continues executing the following code, and exec does not open the child process. Instead, the parent process becomes the new parent process, which is used in conjunction with fork, and any code written after the exec call cannot be run.
Three: Environment variables
%env: Modifying%env can change environment variables without affecting the shell or other parent processes
Four: Anti-quote capture output results
V: Fork for concurrent operations
Fork creates two processes from a process, and if successful, the function returns the newly created subroutine ID to the parent process and returns 0 to the subroutine. If the system does not have enough resources to allocate a new process, the call fails and returns UNDEF.
Parent process can use the Waitpid function to wait for the end of a child process
eg
Output: When the command behavior 0 o'clock, executes the Else section, the system fork automatically gives the value, the PID gets the subroutine ID value, so first executes the parent program segment, then executes the subroutine segment, if appears waitpid in the parent program segment, then enters the subroutine, executes the subroutine and executes the remaining parent program.
Perl Learning (9) Process Management