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


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to output 1s endlessly like /dev/zero?
# 1  
Old 02-26-2010
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
# 2  
Old 02-26-2010
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

# 3  
Old 02-27-2010
Question

Quote:
Originally Posted by pludi
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 02-28-2010
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....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating partitioning setup of /dev/sda on /dev/sdc

Objective: To recreate the partitioning setup of /dev/sda on /dev/sdc How would I parse the below information and initialize variables (an array?) that can be used to build sgdisk commands in a script, regardless of the number of partitions? Something along the lines of: sgdisk -n... (12 Replies)
Discussion started by: RogerBaran
12 Replies

2. Shell Programming and Scripting

Simply question about capturing output to /dev/tty

Suppose another person wrote the following one-line shell script: echo $RANDOM > /dev/tty QUESTION #1: How can the random number, which is output to the terminal by this script, be captured in a variable? QUESTION #2: How can this be done in a cron job? Specific code, whether in ksh or... (1 Reply)
Discussion started by: Paul R
1 Replies

3. Solaris

Lun remove, stuck in /dev/dsk and /dev/rdsk

So, we removed a LUN from the SAN and the system is refusing to remove the references to it in the /dev folder. I've done the following: devfsadm -Cv powermt -q luxadm -e offline <drive path> luxadm probe All those commands failed to remove the path. The drive stills shows up as <drive... (13 Replies)
Discussion started by: DustinT
13 Replies

4. Shell Programming and Scripting

redirect the audio output to /dev/null

I'm using an text-to-speech synthesis in a script, and I need to redirect it's output to /dev/null how can I do that ? And how to redirect the stream to his normal output then (sound card ) ? thankx (2 Replies)
Discussion started by: firelink
2 Replies

5. Shell Programming and Scripting

Error output of cat to /dev/null

Hello, I'm trying to send the error output of a 'cat' operation to /dev/null like this: cat /dirA/dirB/temp*.log > /dirA/dirB/final.log 2>/dev/null This works perfectly in a terminal, but not when placed in a script. If there are no files matching temp*.log the script outputs an error... (7 Replies)
Discussion started by: Nils88
7 Replies

6. Ubuntu

tar not reading if output directed to /dev/null

I stumbled across a somewhat strange behavior of tar and find no explanation for it: i was testing a DVD for read errors and thought to simply tar the content and direct the output to /dev/null: tar -cvf - /my/mountpoint/*ts > /dev/null This way i expected the system to read the complete... (4 Replies)
Discussion started by: bakunin
4 Replies

7. UNIX for Dummies Questions & Answers

Help Understanding Output and question about /dev/

Hi, I am having some problems understanding the info from the following output: Disk /dev/sda: 17849 cylinders, 255 heads, 63 sectors/track Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sda1 *... (5 Replies)
Discussion started by: mojoman
5 Replies

8. UNIX for Dummies Questions & Answers

cp output /dev/null results in not a directory

Hello, I am working on a script to measure the read performance of a busybox environment. The logical choice is to use a command line like: (time cp * /dev/null) 2> /tmp/howlong.txt Ah, the rub is cp or /dev/null will only accept a single file at a time. The result in the txt file is and... (1 Reply)
Discussion started by: stevesmo
1 Replies

9. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

10. Solaris

URGENT - setup port and dump all output to /dev/null or a file

Please help urgently. I need to setup up some sort of service on a solaris server on a port. I dont need it do anything special, anything that is sent to this port from an external server should be dump to /dev/null or a flat file.. Can you help urgently? (1 Reply)
Discussion started by: frustrated1
1 Replies
Login or Register to Ask a Question