LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX
User Name
Password
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.

Notices


Reply
  Search this Thread
Old 09-11-2022, 08:25 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,579
Blog Entries: 30

Rep: Reputation: 173Reputation: 173
"/dev/null" is useful but i would like to have...


in many scripts i create i find "/dev/null" to be a useful fake device, but i would also like to have such a device that just stays "frozen" and has no data available to read. if i had to give it a name, it might be "/dev/no" or "/dev/pause". my use case is running programs that i need to run for certain results but which will or may immediately react to the availability of an immediate EOF they would get from "/dev/null" on STDIN. perhaps such a program only does this on a few *NIX platforms, but it would be good programming to use such a device in the general case for better portability.

i do once remember encountering a device full error writing to "/dev/null" on a *NIX platform. i'm not going to say which it is in the hope that it is now fixed.

Last edited by Skaperen; 09-11-2022 at 08:27 PM.
 
Old 09-11-2022, 10:06 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,668

Rep: Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161Reputation: 2161
Quote:
Originally Posted by Skaperen View Post
in many scripts i create i find "/dev/null" to be a useful fake device, but i would also like to have such a device that just stays "frozen" and has no data available to read. if i had to give it a name, it might be "/dev/no" or "/dev/pause". my use case is running programs that i need to run for certain results but which will or may immediately react to the availability of an immediate EOF they would get from "/dev/null" on STDIN. perhaps such a program only does this on a few *NIX platforms, but it would be good programming to use such a device in the general case for better portability.
What you describe is exactly what /dev/null does. Data written to it is always immediately discarded. Reads from it always return EOF, even if another process is actively writing to it.
Quote:
i do once remember encountering a device full error writing to "/dev/null" on a *NIX platform. i'm not going to say which it is in the hope that it is now fixed.
The way that can happen is if the device special node does not, for some reason, exist, and a process with permission to create files in /dev writes to /dev/null. That creates /dev/null as an ordinary file. The one time I saw something similar to that happen was when the character-special device for a line printer got deleted, and everything being sent to the printer just accumulated in the /dev/lp0 file, filling up that filesystem fairly quickly.

Fortunately, deleting something from /dev requires root privileges on most systems.
 
Old 09-11-2022, 10:39 PM   #3
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 924

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Did you mean: a device that will cause the read to hang or wait, because there's no data available?

Look into pipes or terminals.
ls /dev #for ideas.

Last edited by !!!; 09-11-2022 at 10:51 PM. Reason: https://blog.packagecloud.io/the-definitive-guide-to-linux-system-calls/ # dump 0f /dev/mto / #fills up /dev like LPO LoL
 
Old 09-12-2022, 02:07 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 18,971

Rep: Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434Reputation: 6434
Quote:
Originally Posted by Skaperen View Post
in many scripts i create i find "/dev/null" to be a useful fake device, but i would also like to have such a device that just stays "frozen" and has no data available to read.
Yes, /dev/null is a device which will ignore anything written into it (= like a trash?) but from the other hand you can read from it and it will never give you any data.
Usually when you want to disable stdin you can redirect it to /dev/null:
Code:
whatever_command </dev/null
 
Old 09-14-2022, 01:11 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,579

Original Poster
Blog Entries: 30

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by !!! View Post
Did you mean: a device that will cause the read to hang or wait, because there's no data available?
yes! that is what i mean.

if i am starting up a program that reads what it thinks is a terminal, and if it gets EAGAIN (because it is opened non-blocking) or the like, and calls select() or poll(), there would be no data and no EOF.
Quote:
Originally Posted by !!! View Post
Look into pipes or terminals.
ls /dev #for ideas.
i tried things on a program many years ago. it complained about every non-terminal i tried. terminal types failed for various reasons. a couple caused it to silently crash. i tried a named pipe that was open on the other end and got some error. i think i would need a tty/pty pair with the right code on the other end, but that might be too involved to set up. maybe i should go back and try that one, again, and post code to see if others can see the error of my ways.
 
Old 09-14-2022, 01:19 PM   #6
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,579

Original Poster
Blog Entries: 30

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by pan64 View Post
Usually when you want to disable stdin you can redirect it to /dev/null:
Code:
whatever_command </dev/null
but then the program gets EOF or some error and aborts. i want that program to have it in non-blocking mode, get EAGAIN or the like, do select() or poll() and get nothing from this device. i suspect /dev/null just didn't set errcode in read() and returned zero.
 
Old 09-14-2022, 01:47 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 5,942
Blog Entries: 23

Rep: Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922
It still seems a named pipe (fifo) is what you need.

Maybe this is what you are looking for (from man 7 pipe):

Code:
       If a process attempts to read from an empty pipe, then read(2) will block 
       until data is available. If  a  process attempts to write to a full pipe 
       (see below), then write(2) blocks until sufficient data has been read from 
       the pipe to allow the write to complete.  Nonblocking I/O is  possible  by
       using the fcntl(2) F_SETFL operation to enable the O_NONBLOCK open file 
       status flag.
 
Old 09-16-2022, 01:56 PM   #8
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,579

Original Poster
Blog Entries: 30

Rep: Reputation: 173Reputation: 173
yes, i believe so.
 
  


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
[SOLVED] Stopping cron job emails to root, do I use >/dev/null 2>&1 or &> /dev/null anon091 Linux - Newbie 3 11-12-2013 10:21 AM
What would happen if I where to cat /dev/mem > /dev/null Joey.Dale Linux - General 11 07-26-2009 12:46 PM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 10:51 PM
1> /dev/null 2> /dev/null elyk Programming 9 09-20-2004 05:44 PM
1>/dev/null 2>/dev/null chr15t0 Linux - General 2 07-19-2002 08:37 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX

All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration