LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2013, 02:53 PM   #1
carlitos_30
LQ Newbie
 
Registered: Aug 2013
Posts: 9

Rep: Reputation: Disabled
What does thist mean </dev/null ?


Hello!

I am studying a script and one line says:

clogin -t $timeo -c \"$cisco_cmds\" $host </dev/null > $host.raw 2>&1

I don't undestand the meaning of the "</dev/null" sentence.

I understand this:

> /dev/null

It's redirecting the output to the blackhole file.

But with "<" what could mean?

Thanks!
 
Old 09-10-2013, 02:57 PM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by carlitos_30 View Post
I don't undestand the meaning of the "</dev/null" sentence.

I understand this:

> /dev/null

It's redirecting the output to the blackhole file.

But with "<" what could mean?
that means exactly the opposite: Take the input for the command line from /dev/null.

[X] Doc CPU
 
Old 09-10-2013, 03:12 PM   #3
carlitos_30
LQ Newbie
 
Registered: Aug 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Ok. But what could be the purpose to do that, considering that nothing (for the mere mortal) is inside /dev/null?
 
Old 09-10-2013, 04:17 PM   #4
YellowApple
Member
 
Registered: Mar 2013
Location: Reno, Nevada, United States
Distribution: Slackware, OpenBSD, openSUSE, Android
Posts: 95

Rep: Reputation: 37
Quote:
Originally Posted by carlitos_30 View Post
Ok. But what could be the purpose to do that, considering that nothing (for the mere mortal) is inside /dev/null?
It's handy in the event that you need a dummy input. For example, if you have a program that normally requires some input from STDIN, you can redirect /dev/null as an input file in order to trick the program into thinking it has an input.

One example of this kind of trick is inspecting GCC's behavior; passing /dev/null as an input file allows one to examine quite a bit of GCC's steps in compilation without actually compliling anything.

However, there's a much more important use for this kind of redirection: running a daemon.

See, part of a daemon's operation involves detaching itself from its parent shell process (or some other process it's the child of, like a webserver). Part of this includes detaching itself from said shell by redirecting STDIN, STDERR, and STDOUT to alternate filehandles. /dev/null is commonly used for STDIN, while STDOUT and STDERR may be redirected to /dev/null and/or some logfile.

Most daemons will do this on their own (since most languages support closing and re-opening STDIO filehandles). However, if you're trying to daemonize a program that doesn't daemonize itself (either it's meant to have a controlling terminal or it otherwise doesn't daemonize on its own for some reason), you'll want to make sure that STDIN, STDOUT, and STDERR are detached from the shell. That's where the </dev/null bit comes in.

Note that there are other tasks involved in daemonization, too. However, I imagine this is the context that you'd most often see /dev/null redirected to STDIN.
 
Old 09-11-2013, 04:49 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
What it causes is the application to get a "end of file" condition on stdin as soon as it reads from stdin.
 
Old 09-11-2013, 09:59 AM   #6
carlitos_30
LQ Newbie
 
Registered: Aug 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Studiyng the script it could be the EOF condition mentioned by jpollard.

Not sure.

I am gonna study the daemon thing too.

Thanks all!!!
 
Old 09-11-2013, 05:03 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by carlitos_30 View Post
Studiyng the script it could be the EOF condition mentioned by jpollard.

Not sure.

I am gonna study the daemon thing too.

Thanks all!!!
The daemon thing is most unlikely - as you can't really get a daemon that way. All you get is a process without stdin/stdout/stderr connected to a terminal.

That doesn't create a daemon because becoming a daemon requires the "controlling terminal" to be disconnected (and it isn't - it requires a "setsid" system call though you CAN use a setsid command that does that before executing a command ("setsid command_to_run_new_session parameters...").
 
Old 09-11-2013, 05:36 PM   #8
YellowApple
Member
 
Registered: Mar 2013
Location: Reno, Nevada, United States
Distribution: Slackware, OpenBSD, openSUSE, Android
Posts: 95

Rep: Reputation: 37
Quote:
Originally Posted by jpollard View Post
The daemon thing is most unlikely - as you can't really get a daemon that way. All you get is a process without stdin/stdout/stderr connected to a terminal.

That doesn't create a daemon because becoming a daemon requires the "controlling terminal" to be disconnected (and it isn't - it requires a "setsid" system call though you CAN use a setsid command that does that before executing a command ("setsid command_to_run_new_session parameters...").
That's what I was trying to get at in my explanation: it's not the only thing to do if a process needs to become a daemon, but it's one of them. As you mentioned, yes, some kind of call to setsid() (either via a command or - if you're writing the program yourself - using the appropriate language-specific calls) is also necessary.
 
  


Reply



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] Why is there a need for /dev/null, /dev/zero and other special device (files) in /dev suttiwit Linux - General 13 08-07-2012 12:26 AM
LXer: /dev/null And /dev/zero On Linux And Unix: What's The Difference? LXer Syndicated Linux News 0 04-29-2009 10:50 AM
Startx Permission problems on /dev/null and /dev/mem on freshly compiled 2.6.22.1 Eric_Cartman Linux - Kernel 2 09-09-2007 01:42 AM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 10:51 PM
mv c:\WINDOWS /dev/null; mount /dev/hda treehead LinuxQuestions.org Member Intro 5 10-19-2004 08:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:19 AM.

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