Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-02-2014, 07:55 AM   #1
LQ Newbie
Registered: Jul 2014
Posts: 8

Rep: Reputation: Disabled
what happens when a script running in background calls for standard input?

Im trying to figure out what happens when a background program needs a standard input?.. what exactly happens on the terminal..any help would be appreciated.. thanks
Old 07-02-2014, 11:32 AM   #2
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 3,585

Rep: Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569
If that standard input is from the terminal, the process receives a SIGTTIN signal which will cause it to stop and wait for a SIGCONT signal, which the parent foreground process will presumably send after moving that process back into the foreground, giving it control of the terminal. A shell will typically display a "Stopped" message when one of its background child processes stops that way.
$ (read line; echo got $line )&
[1] 20418

[1]+  Stopped                 ( read line; echo got $line )
$ ps l20418
1   500 20418 20387  20   0 108532  1288 signal T    pts/4      0:00 /bin/bash -
$ fg
( read line; echo got $line )
got hello
(Characters typed at the terminal are in green.)

Last edited by rknichols; 07-02-2014 at 11:36 AM. Reason: added color
Old 07-02-2014, 12:35 PM   #3
LQ Newbie
Registered: Jul 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
awesome.. thanks ..!!
Old 07-02-2014, 05:42 PM   #4
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Now if you logout between putting the process in the background and it trying to read...
there are two possibilities, depending on the shell...

The process gets aborted.

The process gets an I/O error, and depending on the coding, can loop forever.


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
Clearing the standard input in shell script Diptendu Linux - Software 1 09-29-2011 08:33 AM
[SOLVED] How to make a bash script keep running in same terminal after it calls second script? JohnRock Linux - Newbie 4 06-25-2010 10:16 AM
shell script question,standard input,output,error cola Programming 4 04-15-2010 02:11 AM
How to append characters to standard input (telnet script) cep21 Linux - General 1 07-10-2006 02:02 PM
bash script to accept input ONLY until background process completes andrewstr Linux - Software 2 03-17-2004 01:02 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration