18

I understand > /dev/null redirects things to /dev/null which acts like a blackhole. However, I don't understand what < /dev/null means. I saw some script written like this:

nohup myprogram > foo.out 2> foo.err < /dev/null &

So, what does < /dev/null in the code above mean?

here's an example where it's suggested

1

2 Answers 2

20

It ensures that all I/O streams are accounted-for/occupied.

This way, the backgrounded process has nothing "tied" to the terminal so you can go about your business without your program trying to read from TTY, which would cause the terminal to hang.

In this case, since you're launching the process over ssh from a shell script, it's making sure that the script can move along unencumbered.

7
  • Does it assume myprogram takes some input, but in this case it feeds myprogram nothing as input?
    – Qian Chen
    Commented Sep 20, 2015 at 16:46
  • 1
    Thanks. I understand all the rest except the < /dev/null.
    – Qian Chen
    Commented Sep 20, 2015 at 16:49
  • So what's the difference between the code and the same code without < /dev/null?
    – Qian Chen
    Commented Sep 20, 2015 at 16:53
  • I actually read the code from here: stackoverflow.com/questions/29142/…
    – Qian Chen
    Commented Sep 20, 2015 at 16:54
  • 2
    glad it helped! sorry about the runaround; the context helped though, thanks! -- side note: i'm gonna delete a bunch of my comments in a minute or two, now that things are nailed down, it just looks confusing for anyone else who sees it Commented Sep 20, 2015 at 17:48
13

program </dev/null means that the program is taking its input argument (can be input parameter to an option or can be input file to operate on) via file descriptor 0 i.e. STDIN, from the file /dev/null.

As you already know, /dev/null contains nothing, it will notify EOF (End of File) upon read so any program taking input from /dev/null will basically redirecting nothing as its input argument.

4
  • So is there any difference to just leave < /dev/null out? Just write it as nohup myprogram > foo.out 2> foo.err &
    – Qian Chen
    Commented Sep 20, 2015 at 17:31
  • 1
    @ElgsQianChen That depends on your program..what does it want as STDIN ? Some programs might make it mandatory so you need to put something as STDIN, this might be the case here that you just used /dev/null as STDIN and let the program do the processing and put the STDOUT and STDERR in the files mentioned..
    – heemayl
    Commented Sep 20, 2015 at 17:33
  • So does it effectively prevent any input from blocking the process, and just feed nothing to any input request?
    – Qian Chen
    Commented Sep 20, 2015 at 17:36
  • 1
    @ElgsQianChen It will block the file descriptor 0 i.e. STDIN so you can not pass any more input via that..if there is no other FD configured to take input from you won't be able to give any further input to the program..
    – heemayl
    Commented Sep 20, 2015 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .