fork + exec + caller should not wait for child

前端 未结 2 1211
挽巷
挽巷 2021-01-21 09:26

I have two scripts script_a and script_b. script_a calls script_b. script_b forks two processes. As shown below.

script_a waits for both the parent and child of script_b

相关标签:
2条回答
  • 2021-01-21 09:56

    `` backticks in perl wait for the command to complete. So if you don't want parent process to wait put in sytem(command &) in background.

    0 讨论(0)
  • 2021-01-21 10:06

    Instead of using `` in script_a. We have redirected the STDOUT and STDERR in script_a. Something like

    script_a

    system("script_b.pl > /var/tmp/out_file 2>&1");
    

    script_b

    #! /usr/local/bin/perl
    
    $f_id = fork();
    
    if (! $f_id) {
        exec("sleep 10; echo 'i am child'");
    }
    
    if ($f_id) {
        print "i am parent\n";
    }
    

    This way the caller didnot wait for the child in exec to complete.

    Thanks for the help here.

    0 讨论(0)
提交回复
热议问题