[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem using dd within bash script
From: |
Sebastian Rückerl |
Subject: |
Problem using dd within bash script |
Date: |
Fri, 25 Apr 2014 17:18:12 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hello,
Lately I am playing around with some bash scripting that involves dd.
Everything seems to work fine as long as I am not trying to interrupt this
process (using CTRL-C).
Only in this case everything just freezes for some time (for about 1 minute the
terminal is blocked) even if I try to kill it from another terminal using its
pid. This includes that all further CTRL-C are just printed to the terminal and
nothing happens.
My workaround now is to manage all the signal handling on my own. This seems to
work if my only goal was not to have the terminal beeing somehow not
responsive, but it does not kill the dd. (Which can still be seen using ps ax |
grep dd) Anyways dd is somehow interrupted (but not killed totally) as it no
longer responds to kill -USR1.
my current solution is:
----------
#!/bin/bash
# some more things are done in the first place, not related to the dd
dd if=$1 of=$2 bs=4M &
dd_pid=$!
control_c (){
echo "Aborting due to interrupt. Disk will most likely be useless."
kill -9 $dd_pid
exit 1
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
while ps | grep " $dd_pid "
do
# get some status information
kill -USR1 $dd_pid
sleep 3
done
wait $dd_pid
ret=$?
# do some more error handling and continue with the script.
------------
the whole script is executed as root. $1 is a file (image of sd-card), $2 is
the path to the sd-card (e.g. /dev/sdc)
Can those (still somehow running) dd instances do any harm? Or are they just
waiting for something before they can be destroyed?
Thank you for every answer that helps to clearify it all.
Cheers,
Sebastian
signature.asc
Description: Digital signature
- Problem using dd within bash script,
Sebastian Rückerl <=
Re: Problem using dd within bash script, Bernhard Voelker, 2014/04/28