Re: Question about a ' dd ' command.



Peter Garrett wrote:
On Fri, 07 Mar 2008 17:20:03 -0500
elmo <elmo@xxxxxxxxx> wrote:


I read somewhere that these two commands are special application of the
basic 'dd' command that will copy and display the transfer action.


Yes - but these two lines are just an illustration that lasts slightly
more than a second, and does nothing harmful. It just sends a lot of zeros
to nowhere - /dev/null is a useful black hole ;-)


$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

I don't understand the null& and pid=$! in the first line


Attempted explanation follows... The lines you quote are just intended as
an example, as you will see.

$ dd if=/dev/zero of=/dev/null

"Send zeros to the bit bucket" ( that is, to nowhere, if you prefer)

& : Put the previous command in the background.

pid=$! : Store the process number identifying the "dd" process in a
variable named "pid" so we can use it later to send signals to the process.

In this case, the signal " kill -USR1 $pid" tells "dd" to output some
information about what it is doing. See "man signal" ( "kill" doesn't
always mean destruction, in Bash !)

; semicolon divides one command from the next on the command line.

sleep 1 ; Do nothing for one second

kill $pid : Kill the actual process.

Output here looks like this:

$ dd if=/dev/zero of=/dev/null& pid=$!
[1] 16690
$ kill -USR1 $pid ; sleep 1 ; kill $pid
42209510+0 records in
42209510+0 records out
21611269120 bytes (22 GB) copied, 56.7523 seconds, 381 MB/s

As you see, I let it run for nearly a minute.
The alarming-looking 22 GB actually went nowhere, as explained above.



and I don't
understand any of the second line. There doesn't seem to be any
explanation of these anywhere. It appears to me that the writer used
some notations that can be confusing to other guys like me,


Yes, true that it is confusing if you don't already know.
Have a look for example at

http://tldp.org/LDP/abs/html/

For more information.


Is there a more complete discussion of these commands somewhere?

Could someone please show me what the commands
would look like if the simple basic version of ' dd 'is:

dd if =/dev/sda2 of=/dev/sdc3 bs=4096


If you wanted to see periodic information during the process, you could
append "&" without the quotes, to that line, as in the example, and assign
the pid with pid=$!

dd if =/dev/sda2 of=/dev/sdc3 bs=4096 & pid=$!

Then every now and then run

kill -USR1 $pid

The final "kill" after the "sleep" would not be good move, unless you
wanted to stop the dd process, which you probably don't want to do. You
could also stop the "kill -USR $pid" command for example with ctrl+c - the
dd command is by then already in the background ( & ) , so it continues to
completion unless specifically killed with " kill $pid"

dd is powerful and low level, so experiment at your own risk! That's why
the commands used /dev/zero as input and sent them to /dev/null - that's
harmless. If you make a slight error using dd, though, disastrous things
can happen silently ( say, overwriting your whole partition with zeros
unintentionally, and so on. )

Peter


Thanks all.. I'm beginning to get the picture and feel more comfortable
about digging into the references you
mentioned. Now why couldn't the author have taken a few seconds to
supply just a little more clarification?
elmo


--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Relevant Pages

  • Re: [opensuse] Help Killling Process
    ... will not die nor will it display anything. ... I remember from the 'old days' that there is a cli command to ... identify a process id and another one to kill a process. ... This will give you a listing of the processes and their pid' although ...
    (SuSE)
  • Re: 7.1RC1: system hang
    ... pid ppid pgrp uid state wmesg wchan cmd ... Tracing command vmstat pid 96381 tid 100276 td 0xc756caf0 ...
    (freebsd-stable)
  • Re: openoffice.org wont open files on my usb drive
    ... First check whether openoffice is running/not by the following command ... Here you get the process id (pid) of open office ... Kill the process by the following command ...
    (Debian-User)
  • Re: [opensuse] Help Killling Process
    ... I remember from the 'old days' that there is a cli command to ... (the first number for each process is the PID, the second is the PID of the ... Locate the PID for the process you wish to terminate and use the 'kill' ... To kill the xterm process in the above example, ...
    (SuSE)
  • Re: killing child processes
    ... It's that the kill command does nothing. ... >> UID PID PPID TTY STIME COMMAND ... but not the sleep command that is it's ...
    (comp.unix.shell)