Perl Learning (9) Process Management

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.