MJN All Blog Cheatsheets Elasticsearch GCP JS LinuxBash Misc Notes Other ShortcutKeys / - Search

Home / LinuxBash / Waiting On Background Processes


Contents

The wait command waits for all background processes start in the current session to end.

#!/bin/bash

function f1() {
  echo "process 1, sleeping 3s"
  sleep 3
  echo "process 1 complete"
}

function f2() {
  echo "process 2, sleeping 2s"
  sleep 2 
  echo "process 2 complete"
}

f1 &
f2 &

wait

echo "all done

Output:

$ xxx
process 1, sleeping 3s
process 2, sleeping 2s
process 2 complete
process 1 complete
all done

$

This page was generated by GitHub Pages. Page last modified: 22/03/07 18:20