Solved

Communicate with a background process

Posted on 2004-08-02
7
694 Views
Last Modified: 2013-12-26
Hi,

I would like to know the various possible ways to communicate with a background proces.

I need to write a program that runs in the background and take commands from any other process/command
and take necessary action...

An example of such a program (both background process and a communcator to this process) would be great.
Possibly a perl/shell script...

I know this can be done with sockets but I want to know about other possiblities. Actually, I dont want to use sockets.

Thanks,
Venkat.
0
Comment
Question by:venkateshwarr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 300 total points
ID: 11700623
sockets is the cleanest way to do this ... ofcourse there are other possibilities such as shared memory

communicator puts the command in shared memory and background process reads commands from shared memory. Same mechanism can be used for communicating back the results ...
Both the processes can either run in polling mode to see if new command/data has arrived or they can communicate asynchronously using signals

another option will be to use message queues or shared buffer just like you would have used in a producer consumer mechanism

there can be other possibilities but the biggest drwback for all of these will be the scalability ... What if tomorrow you have 50 processes trying to get their commands executed by the background process ? How will you manage the shared memory or synchronize access to queue ?

I would recommend the socket (either TCP or unix domain) approach
0
 
LVL 2

Assisted Solution

by:sin_
sin_ earned 50 total points
ID: 11701122
Socket could be the best way but you can think of some other ways like Shared Memory  and SOlaris Doors ( if you are working on Solaris).

Synchronization with Shared Memory may lead to a big mess. So do take care of all that while designing your program.
0
 
LVL 1

Assisted Solution

by:dmwaff
dmwaff earned 100 total points
ID: 11708585
Since this posted under UNIX, I am assuming UNIX.

Check process handling under KORN shell, more specific  -- coroutines with two-way pipes.

If you start a bg process by appending |& to a command instead of &, the KORN shell will set up a special two-way pipeline between the parent shell and the new background process.

read -p in the parent shell reads a line of the bg process' stdout; similarly print -p in the parent shell feeds into the stdin of the bg process.

EXAMPLE:
vi mycal
#!/usr/bin/ksh

bc |&

while read line'?mycal> '
do
print -p "$line"
read -p answer
print " = $answer"
done

OUTPUT:
$ ./mycal
mycal> 2+5
 = 7
mycal> ^D
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Author Comment

by:venkateshwarr
ID: 11711647
Thanks for all the comments... I will get back to you guys soon.

venkat.
0
 
LVL 4

Assisted Solution

by:alikoank
alikoank earned 50 total points
ID: 11725999
What you ask is called Inter Process Communication (IPC) there are at least five methods of accomplishing it.

there are various different documents on this topic

http://users.actcom.co.il/~choo/lupg/tutorials/multi-process/multi-process.html

choose one that suits best to your project.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11733869
> Possibly a perl/shell script...
see Camelbook, contains a full functioning example (to huge to post here)
0
 
LVL 12

Author Comment

by:venkateshwarr
ID: 12199716
Thanks guys for ur answers.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question