Tags:
create new tag
, view all tags
/dev/null is a character special device node in UNIX, Linux and similar systems. Unlike most of the other device nodes this one doesn't connect to a physical hardware device --- rather it simply behaves '''like''' a device (sometimes called a psuedo-device). It can be opened, (using the ''open()'' system call), written to (using ''write()'') and read from (using ''read().''

Writing to /dev/null always succeeds. The output is simply discarded. Thus /dev/null is also called the "BitBucket" (a place to throw away unwanted output. Thus it is commonly used in shell commands to redirect output (>/dev/null or 1>/dev/null) or error messages (2>/dev/null) or both (>/dev/null 2>&1).

Reading from /dev/null should always return EOF (EndOfFile). This is occasionally useful for force a program NOT to attempt to read from one's terminal. However, /dev/null is used to discard information far more often than to block inputs.

It is common for daemons to close their standard file descriptors (stdin, stdout, and stderr) and then open new ones on /dev/null (usually using the ''dup()'' system call (or the ''fdup()'' library function wrapped around it) to duplicate stdout and stderr on the same stream. This ensures that any library functions or other parts of the program can write to these standard file descriptors while also ensure that they aren't connected to any terminal or device.

This device should NOT be confused with /dev/zero. While reading from /dev/null returns 0 bytes of input (and indicates an EOF), reading from /dev/zero returns and endless stream of ASCII NUL characters (which is the "zero" 0 character in that set). (I'm not sure what it returns on the rare EBCDIC or other non-ASCII UNIX system; presumably still a stream of "zero" bits; whatever character that is to that architecture). (Writing to /dev/zero is undefined in the POSIX spec.? Thus it might succeed as with /dev/null, or it might return an error as if the device was full: EINVAL, EIO, or ENOSPC are possible errors in that case. Linux seems to simply allow writes to /dev/zero without error or complaint)

Contributors

  • () JimDennis - 22 Oct 2003
  • If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your WikiName.

[[Main.JimDennis#22 Oct 2003][]]

Topic revision: r1 - 2003-10-22 - JimDennis
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look