LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2012, 09:50 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Rep: Reputation: 51
An example from the dd manual.


Kernel 2.6.21.5, Slackware 12.0

Hi:
Code:
       Sending a USR1 signal to a running `dd' process makes it print I/O sta-
       tistics to standard error and then resume copying.

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

              18335302+0  records  in  18335302+0 records out 9387674624 bytes
              (9.4 GB) copied, 34.6279 seconds, 271 MB/s
How does 'pid=$!' fit into the dd syntax? Is the first line a single command? The meaning of 'pid=$!' is clear to me. As a second question, why to sleep 1, then kill $pid? 'kill -USR1 $pid' would do exactly what is intended that is, print and resume copying.
 
Old 02-17-2012, 09:56 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Hey STF,

I use this approach myself sometime. Anyway, here's my clarification of that example (which is exactly that, an example of little practicality.)

Code:
# Write from /dev/zero into /dev/null, and do it in the background (note the &.)
dd if=/dev/zero of=/dev/null &

# Get the pid of whatever the last backgrounded process was (see bash man page.)
# Note that this is a new, separate statement, not an argument to dd,
# as could be mistaken from the original text.
pid=$!

# Now, print out the progress using USR1 interrupt. 
kill -USR1 $pid;

# The sleeping makes the behavior more clear in the example, but probably isn't necessary.
sleep 1;

# Okay, examples over. Actually kill (terminate) the process.
kill $pid
 
Old 02-17-2012, 11:21 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Oh thanks, jhwilliams. I knew the meaning of pid=$! as I had looked for ! in the bash man. pid is an arbitrary name, and $! extracts the value of !. But in the first line of the example, there is not a semicolon (';') to separate the two commands. But bash interpreted the right way! It seems as if, after an ampersand, the semicolon is superfluous.

By the way, what is the meaning of USR1 or a reference to it. I have a demo board, able to run linux (embedded) with two LEDs (light indicator) , USR0 and USR1.
 
Old 02-17-2012, 11:32 AM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Checkout the entry for signal in section 7 of the man pages on your platform:

Code:
man 7 signal
[quote] there is not a semicolon (';') to separate the two commands[/code]

This has got me before, too. It's more confusing in a for loop syntax:
Code:
 for item in $list; do background_job $item & done
Which just looks wrong, but isn't.

Last edited by jhwilliams; 02-17-2012 at 11:35 AM.
 
1 members found this post helpful.
Old 02-17-2012, 11:35 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Thanks a lot!
 
Old 02-17-2012, 11:35 AM   #6
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
NP :-)
 
Old 02-18-2012, 12:44 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
I rushed to consider the thing solved: What makes ';' redundant?
 
Old 02-18-2012, 12:50 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by stf92 View Post
I rushed to consider the thing solved: What makes ';' redundant?
http://www.gnu.org/software/bash/man...ref.html#Lists
 
1 members found this post helpful.
Old 02-18-2012, 01:05 PM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Ahhh, '&' acts as a separator too,and with the same precedence as ';'! Most kind of you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yast Manual carlahrcruz Linux - Distributions 1 02-03-2012 11:09 AM
man -t manual | ps2pdf - > manual.pdf error Amdx2_x64 Linux - General 2 07-01-2011 04:22 AM
Manual Install delite Linux - Newbie 5 04-20-2009 05:35 PM
no manual pages sycamorex Debian 2 09-12-2006 06:04 AM
Why manual startx? sikandar Linux - Software 9 09-13-2003 11:15 AM


All times are GMT -5. The time now is 05:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration