From 26af14c0a67ee2ec7c99b42730e705f26e1fd23f Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Mon, 1 Aug 2022 15:15:01 -0700 Subject: [PATCH] Removing unfinished file --- lib/background.sh | 63 ----------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 lib/background.sh diff --git a/lib/background.sh b/lib/background.sh deleted file mode 100644 index 5c950e1..0000000 --- a/lib/background.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -# vim: ft=bash -# @copyright © 2016-2022 Konstantin Gredeskoul, All rights reserved -# @license MIT License. -# -# @file lib/background.sh -# @description Run a bunch of jobs on the background and wait for their completion - -declare -a running_jobs -declare -a completed_jobs - -declare background_log=$(mktemp -t "bashmatic.bg-{{index}}.log") - -function background.log() { - local index="${1:-0}" - printf "${background_log/{{index}}/${index}}" -} - -function background.sigchld() { - for pid in "${!running_jobs[@]}"; do - if [ ! -d "/proc/$pid" ]; then - wait "${pid}" - local code="$?" - running_jobs["${pid}"]=${code} - fi - done -} - -function background.run() { - for command in "$@"; do - local index=${#running_jobs[@]} - local log="$(background.log "${index}")" - (${command} 2>&1 | tee -a "${log}") & - running_jobs[$!]=-1 - done -} - -function background.wait() { - local timeout -echo Starting background processes with pidS ${!pidS[@]} -echo Starting dd -timeout 15s dd if=/dev/zero of=/dev/null -echo dd terminated - -} - -trap background.sigchld SIGCHLD - -( - sleep 9 - exit 44 -) & -pidS[$!]=1 -( - sleep 7 - exit 43 -) & -pidS[$!]=1 -( - sleep 5 - exit 42 -) & -pidS[$!]=1