Solved

Communicate with a background process

Posted on 2004-08-02
7
692 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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