Solved

Communicate with a background process

Posted on 2004-08-02
7
688 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 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now