LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 07-01-2007, 12:42 AM   #1
rajaniyer123
Member
 
Registered: Feb 2004
Location: BARODA, GUJARAT
Posts: 259

Rep: Reputation: 30
Diff Between /dev/zero & /dev/null


Hi

As I would like to know the difference between

cp /dev/zero /var/tmp/testfile
cp /dev/null /var/tmp/testfile

with ref of the starving the system of its resources


Thanks
Rajan
 
Old 07-01-2007, 01:41 AM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 61
(From Wikipedia)
/dev/zero provides as many ASCII null characters as read from it. The characters returned are 0x00, not the letter 0. Any writes to /dev/zero are successful, with no other side effects.

/dev/null can not be read from - any reads will return an EOF.

Now, why would you want to starve the system of its resources? This sounds suspiciously like hacking to me, which is not acceptable at LQ.

--Ian
 
Old 07-01-2007, 01:54 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
/dev/null is a sink. It is commonly used to redirect stderr to. In a cron script, you can't write to the console so you would redirect both stdout and stderr to /dev/null.

/dev/zero is a source of 0 bytes. You can use it when creating a zeroed out file, which can then be used to create a filesystem on:
dd if=/dev/zero of=imagefile bs=512 count=$((2*1024*64))
/sbin/mkfs.ext3 imagefile

Now you have an image file you can mount using the loopback device:
sudo mount -t ext3 image.img mountdir/ -o loop
sudo chown username:username mountdir
sudo chmod 007 mountdir

----

Sorry Iball, you posted your message first, and I was too dense to notice the potential hacking aspect of the question.

Last edited by jschiwal; 07-01-2007 at 01:56 AM.
 
Old 07-01-2007, 04:46 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Quote:
Originally Posted by jschiwal
/dev/zero is a source of 0 bytes. You can use it when creating a zeroed out file, which can then be used to create a filesystem on:
dd if=/dev/zero of=imagefile bs=512 count=$((2*1024*64))
/sbin/mkfs.ext3 imagefile

Now you have an image file you can mount using the loopback device:
sudo mount -t ext3 image.img mountdir/ -o loop
sudo chown username:username mountdir
sudo chmod 007 mountdir
Please note that while a good example of /dev/zero use, these commands are more or less Linux specific.
Here is what I would do to achieve the same result under Solaris
Code:
mkfile -n $((2*1024*64*512)) imagefile
device=$(lofiadm -a $PWD/imagefile)
rdevice=$(echo $device | sed 's/lofi/rlofi/')
yes | newfs $rdevice
mountdir=/mnt/image
mkdir $mountdir
mount $device $mountdir
chown username:groupname $mountdir
chmod 0700 $mountdir
Or with ZFS, the quite simpler:
Code:
mkfile -n $((2*1024*64*512)) imagefile
zpool create imagefile
About the resource starving question, "cp /dev/zero ..." will eventually fill up the target filesystem unless quotas are in place.
OTOH "cp /dev/null ..." would create an empty file. No big deal.

Last edited by jlliagre; 07-01-2007 at 05:35 AM.
 
Old 07-02-2007, 07:09 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Quote:
Originally Posted by jlliagre
Please note that while a good example of /dev/zero use, these commands are more or less Linux specific.
Here is what I would do to achieve the same result under Solaris
Thanks for that. I used the rss feed in firefox and failed to notice the forum I was in.
 
  


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
What would happen if I where to cat /dev/mem > /dev/null Joey.Dale Linux - General 11 07-26-2009 01:46 PM
/dev/null 2>&1 ??????????? waelaltaqi Linux - General 2 05-17-2007 11:22 PM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 11:51 PM
> /dev/null 2>&1 blackzone Linux - Newbie 2 09-20-2004 05:10 AM
> /dev/null 2>&1 Sammy2ooo Linux - Software 2 07-16-2003 10:20 AM


All times are GMT -5. The time now is 04:48 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration