Skip to content

Instantly share code, notes, and snippets.

@CristianCantoro
Last active May 25, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CristianCantoro/b36189b4e0e1b83abee3d92546010e42 to your computer and use it in GitHub Desktop.
Save CristianCantoro/b36189b4e0e1b83abee3d92546010e42 to your computer and use it in GitHub Desktop.
Testing `nohup`, `&` and `disown`
#!/usr/bin/env bash
# shellcheck disable=SC2128
SOURCED=false && [ "$0" = "$BASH_SOURCE" ] || SOURCED=true
if ! $SOURCED; then
set -euo pipefail
IFS=$'\n\t'
fi
mypid="$$"
echo -e "[${mypid}]\\t=> I am going to launch a process"
./sleep.sh 90 &
echo -e "[${mypid}]\\t=> I have launched a process"
atime=60
echo -e "[${mypid}]\\t=> I am goig to sleep for ${atime} s"
for i in $(seq 1 "${atime}"); do
echo -e "[${mypid}]\\t=> ${i}"
sleep 1
done
echo -e "[${mypid}]\\t=> I have launched a process"
exit 0
#!/usr/bin/env bash
# shellcheck disable=SC2128
SOURCED=false && [ "$0" = "$BASH_SOURCE" ] || SOURCED=true
if ! $SOURCED; then
set -euo pipefail
IFS=$'\n\t'
fi
atime="$1"
mypid="$$"
sleep 5
echo -e "[${mypid}]\\t=> I am going to sleep for ${atime} s..."
for i in $(seq 1 "${atime}"); do
echo -e "[${mypid}]\\t=> ${i}"
sleep 1
done
echo -e "[${mypid}]\\t=> I have slept for ${atime} s"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment