Skip to content
Snippets Groups Projects

bash process synching

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by cyberta

    Proof of Concept to showcase that https://0xacab.org/leap/obfsvpn/-/merge_requests/29 correctly handles the obfsvpn server and control plane shutdown once either of both processes finish

    Edited
    test2.sh 49 B
    #!/bin/bash
    
    set -e
    
    sleep 10
    echo "crash"
    exit 1
    test3.sh 73 B
    #!/bin/bash
    
    set -e
    
    while true
    do
        echo hello world
        sleep 1
    done;
    test_sync_2_background_processes.sh 231 B
    #!/bin/bash
    
    set -e
    
    trap "exit" INT TERM
    trap "kill 0;" EXIT
    
    ./test2.sh &
    PID1=$!
    
    ./test3.sh &
    PID2=$!
    
    export PID1 PID2
    ( tail -f --pid=$PID1 /dev/null; kill $PID2; ) &
    ( tail -f --pid=$PID2 /dev/null; kill $PID1; ) &
    
    wait -n 
    test_synch_fg_and_bg_process 439 B
    #!/bin/bash
    
    set -e
    
    kill_foreground() {
        echo "Background script has finished. Killing foreground script."
        ps -C "test3.sh" -o "%p"| grep -v PID | xargs kill;
    }
    
    kill_background() {
        echo "Foreground script finished. Killing background script."
        kill 0;
    }
    
    
    trap "exit" INT TERM
    trap "kill_background" EXIT
    
    ./test2.sh &
    
    export PID1=$!
    ( tail -f --pid=$PID1 /dev/null; echo "kill test3.sh "; kill_foreground ) &
    
    ./test3.sh
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment