File: spawn_children.sh

package info (click to toggle)
con-duct 0.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 608 kB
  • sloc: python: 4,332; sh: 22; makefile: 18
file content (28 lines) | stat: -rwxr-xr-x 632 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

mode=$1
nchildren=$2
sleeptime=$3

# Ensure at least one background process for `wait` to track, we want this to take longer than the children.
long_sleep=$(awk "BEGIN {print $sleeptime * 1.5}")
sleep "$long_sleep" &

for _ in $(seq 1 "$nchildren"); do
    case "$mode" in
        subshell)
            ( sleep "$sleeptime" & ) ;;
        nohup)
            ( nohup sleep "$sleeptime" & disown ) & ;;
        setsid)
            setsid sleep "$sleeptime" & ;;
        plain)
            sleep "$sleeptime" & ;;
        *)
            echo "Unknown mode: $mode" >&2
            exit 1
            ;;
    esac
done

wait