1828240 Members
2355 Online
109975 Solutions
New Discussion

Blocking on /dev/null

 
SOLVED
Go to solution
Ed Hon
Regular Advisor

Blocking on /dev/null

Will multiple processes writing to /dev/null block on each other or run as if they had their own copy of the file?
3 REPLIES 3
Dan Hetzel
Honored Contributor

Re: Blocking on /dev/null

Hi Ed,

You can have as many processes as you want writing to (or reading from) /dev/null without blocking, within the kernel limit for maximum processes or files open, of course.

Writing to /dev/null simply discards data, while reading from always returns 0 bytes.

I don't know exactly how this is implemented but I guess that there is a special hook in the kernel code to achieve this.


Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
John Palmer
Honored Contributor
Solution

Re: Blocking on /dev/null

Hi Ed,

They won't block as /dev/null isn't a regular file, it's a 'pseudo driver' special file.

Data written to it will be handled by a kernel routine which simply does nothing with it - throws it away.

If you do 'fuser /dev/null' you'll find that many of your server's processes will have /dev/null open.

Regards,
John
Gregory Fruth
Esteemed Contributor

Re: Blocking on /dev/null

I don't think /dev/null blocks on read or write. Note that
reading from /dev/null always returns 0 bytes, and NOT
an endless stream of zeroes (which some systems provide
via the special file /dev/zero).

Processes might block on writing to /dev/null if someone
has acquired a lock on it, and the processes honor the lock,
or if someone has acquired an enforced lock on it. /dev/null
should NOT have the enforcement bit set, so the latter case
shouldn't be possible. (The lock enforcement bit is the same
as the setgid bit.)