UnixServerAdmin

Server Administration & Management

Difference between /dev/null and /dev/zero files

/dev/zero and /dev/null are two pseudo files which are useful for creating empty files. Many people consider there is no difference or puzzled with what could be the difference between two files. There is considerable difference when writing data using these hardware files.

/dev/zero: This file is used to create a file with no data but with required size(A file with all zero’s). In other words this will create a data file with all zeros in the file which will give the size to a file. If you see the strace command on /dev/zero, it’s continuous zeros which it will write to a file. So we conclude that /dev/zero is a file use full for creating a file with some required size without any meaning to the data.

/dev/null: This is one more Pseudo file which is useful in many places like redirecting unwanted output/error etc to this file. This file acts as a black hole(Which eat up everything and do not show any output). So whenever you feed some data to this file, you can not retrieve the data which is fed to it. This file even useful for creating files with zero size.

Advertisements

July 30, 2014 Posted by | Tips & Tricks, Unix/Linux | , , , | Leave a comment

Why swap is double the size of the RAM in Linux

It has a meaning and for that we should know memory hierarchy. We have different levels of memory which is useful for processing your data. They are as follows.

  • Processor/CPU registers(Bits in size)
  • L1 Cache(kbs in size)
  • L2 Cache(MBs in size)
  • L3 cache(100s of MBs in size)
  • RAM(GB’s in size)

suppose take one application which is in running state. The application data is moved to RAM for faster accessing and some of its data is moved to L3 cache for processing frequently used data and we move more frequently used app data to L2 and then L1. And we move data which is right now processed by your processor/CPU to registers which is present in processor. If you observe the memory size will gradually decrease when you go up in the ladder more frequently used data is kept at higher levels and made it self available for processing. So if suppose you want to load a bigger program which can consume all the ram/L3/L2/L1 cache its better to move already running process to some location which we can access later to process it once again. But moving this data to HDD is not preferred as it is bit slow and other solution is to increase the RAM size which bit cost. So people came with a solution called SWAP partition which can solve both these limitations.

We create swap partition to cache all the data in registers, L1, L2, L3 caches and RAM.

Then why we create two times the RAM :–>  The reason behind it is that if you club all the above memory locations, the total size will be between 1.5 times to 2 times the RAM. This is the reason behind the thumb rule to create swap size 2 times the RAM

If I create swap size more than two times the RAM, What will happen –>  As we said earlier swap is used to move data from different memories and their total size is always 1.5 times to 2 times maximum so it’s of no use if you create swap size more than 2 times the RAM. In other words, all the space more than 2 times the RAM in swap is no use.

I have RAM size of 128GB and my RAM usage never fills up, do I have to create swap partition –> No, not at all required. As mention earlier swap is a temporary space to store all your memories data for future processing, if your RAM is free then there is no use of swap partition.

July 20, 2014 Posted by | Tips & Tricks, Unix/Linux | , , , | Leave a comment

Why we can create only up to 4 primary partitions

Actually in basic hard disk, we can create 4 partition(either primary or extended), we can create

  • 4 primary maximum or
  • 3 primary + 1 extended or
  • 2 primary + 1 extended or
  • 1 primary + 1 extended

not more then that? why and what is the reason?

The reason is because of a limitation of the MBR (Master Boot Record- the first sector of the hard disk.) The MBR is only 512bytes of size, it is needed to store the primary boot loader, and the partition table. Typically, the area reserved for partition table is only 64 bytes. And the partition table entry for one partition is 16 bytes. So, 16×4=64. The space is over. so we cant create more than this.

July 10, 2014 Posted by | Tips & Tricks, Unix/Linux | , , , | Leave a comment