Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Communicate with a background process

Posted on 2004-08-02
7
Medium Priority
?
724 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
7 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 1200 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 200 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 400 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
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!

 
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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

877 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