Unix/Linux Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

learn linux and unix commands - unix shell scripting

How to output 1s endlessly like /dev/zero?

UNIX for Advanced & Expert Users


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-26-2010   -   Original Discussion by LessNux
LessNux's Unix or Linux Image
LessNux LessNux is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 25 February 2014, 10:15 PM EST
Posts: 40
Thanks: 14
Thanked 1 Time in 1 Post
Unix or Linux Question How to output 1s endlessly like /dev/zero?

/dev/zero can output 0's (null characters) endlessly. I am looking for a technique to output 1's (0xFF or 0b11111111) endlessly in a similar manner as /dev/zero.

The following dd statement writes 4 terabytes of 0's to the drive /dev/sdb. This dd statement does not cause any memory shortage.



Code:
dd bs=4K count=1G if=/dev/zero of=/dev/sdb

On the other hand, I would like to write 1's almost endlessly. The following perl statement attempts to write 4 terabytes of 1's. However, its huge buffer at the redirection causes the "Out of memory" error, and hence the perl statement fails.



Code:
perl -e 'print "\xFF\xFF\xFF\xFF"x1024x1024x1024x1024' > /dev/sdb

Is there any technique to output 1's (0xFF or 0b11111111) endlessly in a similar manner as /dev/zero? I wonder if this goal can be achieved by using /dev/loop or something.

Thanks a lot in advance.


----------

Mac OS X note: The dd command on Mac OS X has slightly different syntax from that on Linux. The dd command on Mac OS X may expect lowercase letters for k, m and g. If the above dd statement does not work on Mac OS X, try the following.

dd bs=4k count=1g if=/dev/zero of=/dev/disk1

Last edited by zxmaus; 02-27-2010 at 02:36 AM.. Reason: added code tags
Sponsored Links
    #2  
Old Unix and Linux 02-26-2010   -   Original Discussion by LessNux
pludi's Unix or Linux Image
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,521
Thanks: 38
Thanked 335 Times in 308 Posts
The first question I have to ask is "WHY?"

And the resolution is simple. dd reads from stdin by default so just let it:

Code:
perl -e 'print chr(0xFF) while(1);' | dd of=/dev/sdb

Sponsored Links
    #3  
Old Unix and Linux 02-27-2010   -   Original Discussion by LessNux
LessNux's Unix or Linux Image
LessNux LessNux is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 25 February 2014, 10:15 PM EST
Posts: 40
Thanks: 14
Thanked 1 Time in 1 Post
Unix or Linux Question

Quote:
Originally Posted by pludi View Post
the resolution is simple.


Code:
perl -e 'print chr(0xFF) while(1);' | dd of=/dev/sdb

Thanks, pludi. However, is there any faster technique?

The technique "perl -e 'print chr(0xFF) while(1);'" is too slow compared to /dev/zero.

The "perl ... while" method is 400 times slower than /dev/zero, if there is almost no bottleneck by the output destination.

Even in a real world environment where the flow is bottlenecked by the slow hard drive, the "perl ... while" method is 2.5 times slower than /dev/zero.

Can anyone think of a technique to output 1's (0xFF or 0b11111111) endlessly nearly as fast as /dev/zero? Is it possible to custom-make a pseudo-device similar to /dev/zero?

Thanks a lot in advance.
    #4  
Old Unix and Linux 02-28-2010   -   Original Discussion by LessNux
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 6 January 2018, 9:59 PM EST
Location: NM
Posts: 11,276
Thanks: 581
Thanked 1,123 Times in 1,035 Posts
This is one of those questions which really begs for:
What do you need to do - exactly? Not how you decided it should be done.

/dev/zero and /dev/null are kernel device drivers implemented by kernel code
Have fun:
linux-v2.6.33-rc6/drivers/char/mem.c | ERTOS Source Browser


One of the reasons perl is "slow" is because it is an interpreted language, not a compiled language. There are lots of disk scrubber apps out there....
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
top output for six processes with the same name, output changed from column to row Bloke Shell Programming and Scripting 5 06-04-2009 07:02 AM
capturing output from top and format output new2ss Shell Programming and Scripting 4 02-24-2009 09:26 PM
Command display output on console and simultaneously save the command and its output satimis UNIX for Dummies Questions & Answers 7 01-25-2009 08:27 PM
Expect - Interact output hangs when large output natedog Shell Programming and Scripting 0 08-27-2008 12:21 PM
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 08:30 AM



All times are GMT -4. The time now is 12:06 AM.