#!/bin/sh locker() { while ! mlock; do echo "mlock died!!! $?" sleep 0.5 done } matcher() { while ! ./facematcher.py match -d 2 faces/martin/*; do echo "facematcher died!!! $?" sleep 2 done } trap 'kill $(jobs -p)' EXIT locker & lockerpid=$! matcher & matcherpid=$! while :; do if ! kill -0 $lockerpid; then kill $matcherpid wait exit 0 elif ! kill -0 $matcherpid; then kill $lockerpid pkill i3lock wait exit 0 fi sleep 1 done