LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-11-2002, 01:26 PM   #1
cdex
LQ Newbie
 
Registered: Aug 2002
Location: near berlin, germany
Distribution: Debian unstable
Posts: 11

Rep: Reputation: 0
Question bash: interaction with background processes ...


hello,
i've a question for which i cant find an answer :

is it possible to pass commands to background processes ?

For example, to pass an "here document" to an interactive program which was forked into the background ...

what i want to do is following:
running mpg321 (with remote control interface .. ) in the background ( # mpg321 -R xxx & ) and then i need to pass its command codes to it (in the background) via a shell script ...

does anyone know, if this works (and how? ) ?
 
Old 08-11-2002, 01:30 PM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Yes, there is a roundabout way of doing it.

First, make a fifo (this basically works like a file):

mkfifo foo

Now run your program in the background:

program &

Now to send your program commands:

echo 'command string' > foo

I just tried this out and it worked for me, hope it's useful.
 
Old 08-11-2002, 01:32 PM   #3
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Oops, forgot the important bit...That should have been:

program < foo &

Last edited by llama_meme; 08-11-2002 at 01:43 PM.
 
Old 08-11-2002, 02:04 PM   #4
cdex
LQ Newbie
 
Registered: Aug 2002
Location: near berlin, germany
Distribution: Debian unstable
Posts: 11

Original Poster
Rep: Reputation: 0
yeah ... thanks, this worx great !

now, i just have to look what i'm doing with the output ... (bcause it outputs to stdout/stderr although its in background ... )
 
Old 08-11-2002, 02:17 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965Reputation: 1965
a *slightly* easier method (maybe):

tail -f messagefile | program &

echo messge >> messagefile

should be simlpe enough to adapt to taking stdout too... probably with a following tail aswell.
 
Old 08-11-2002, 02:42 PM   #6
cdex
LQ Newbie
 
Registered: Aug 2002
Location: near berlin, germany
Distribution: Debian unstable
Posts: 11

Original Poster
Rep: Reputation: 0
cool, this works also ....

i tried it with brackets:
# (tail -f msgfile | mpg123 -R xxx ) &

but the first method fits for me better, because it doesn't access filesystem ... ( better for NFS-root )
 
  


Reply

Tags
fifo, redirection


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
Redirecting output of background processes after they've been started (BASH) DaneM Programming 18 08-08-2011 09:03 PM
send commands to background processes chatterbug89 Linux - General 2 07-13-2005 03:55 PM
background processes digit Linux - Software 3 07-27-2003 12:27 PM
processes in background zetsui Linux - General 8 06-14-2003 12:52 PM
background processes hakum Programming 1 04-08-2002 10:29 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration