Solved

Communicate with a background process

Posted on 2004-08-02
7
700 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
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 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