john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Bash background process pid kill wait

!/bin/bash

start the background script, then find the pid

myscript.sh & myscript_pid=$! echo "do some stuff" kill -9 $myscript_pid


!/bin/bash

maybe someone else started the background script myscript

myscript_pid=$(pidof myscript) echo "do some stuff" kill -9 $myscript_pid


!/bin/bash

wait until both scripts are done, allow control + c termination

function continuous() { date myscript.sh & anotherscript.sh & wait || return }

while true ; do continuous 2>&1 | tee -a $LOG sleep 10 || break done


  • « requests binary download chunked temp directory os stat change modified timestamp
  • Email server postfix smtp relay »

Published

Jun 17, 2014

Category

linux

~66 words

Tags

  • background 3
  • bash 7
  • kill 4
  • pid 1
  • process 6
  • scripts 63
  • wait 2