fork + exec + caller should not wait for child

前端 未结 2 1213
挽巷
挽巷 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 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.

提交回复
热议问题