LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 03: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, 03: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: 343Reputation: 343Reputation: 343Reputation: 343
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, 04: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, 05:17 PM   #4
YellowApple
Member
 
Registered: Mar 2013
Location: Truckee, California, United States
Distribution: Slackware, OpenBSD, openSUSE, Android
Posts: 92

Rep: Reputation: 35
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, 05:49 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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, 10: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, 06:03 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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, 06:36 PM   #8
YellowApple
Member
 
Registered: Mar 2013
Location: Truckee, California, United States
Distribution: Slackware, OpenBSD, openSUSE, Android
Posts: 92

Rep: Reputation: 35
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


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


All times are GMT -5. The time now is 10:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration