communication between shell and and a demon 'c' program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting communication between shell and and a demon 'c' program
# 1  
Old 07-24-2011
communication between shell and and a demon 'c' program

Hello,
i have a demon 'c' program that have a dynamic table of logic registers ( 2000 variables ).
exemple of registers:
I1.34.5
M23.4.1

I want from shell acess to this table of registers.
How can i do this?

with something like for read I1.34.5:
#cat /sys/class/mySoftware/mapping/I/1/34/5
#echo 98 > /sys/class/mySoftware/mapping/I/1/34/5
# 2  
Old 07-25-2011
There are ways to do this from the daemon:
1. write to a known memory location in a given process - like a message queue or shared memory.
2. write to a named pipe or to a given filename

The is nothing you can do in shell by itself; you have to seriously rewrite the daemon.
# 3  
Old 07-25-2011
Also event method is nice. daemon is trivial and not poll anything if both: daemon + client use signals = very hw friendly.

Daemon:
Code:
sometodo()
{
   # do the client files
   :
}

trap 'sometodo' 2
while true
do
        sleep 10000
done

Daemon trap some signal ex. 2 in previous code.

Client create some own file like $$.mydata.ask:
Code:
MYPID=$$
MYNEED=I/1/34/5
MYANSWERFILE=$$.mydata.answer

Then send signal for daemon
Code:
kill -2  $DAEMONPID

Then daemon catch the signal 2 and read some directory.
There is NNN.mydata.ask files
Run those files in same process:
Code:
.  NNN.mydata.ask
echo "$(date '+%Y%m%d%H%M%S') NNN.mydata.ask" >> somelog
cat NNN.mydata.ask >> somelog
rm -f NNN.mydata.ask

Then do the ...
And write answer to the file $MYANSWERFILE.tmp
and give the answer for client which poll this file

Code:
mv $MYANSWERFILE.tmp $MYANSWERFILE

Ofcourse it's also possible that client create subprocess, give that PID number for daemon. Daemon send signal for that dummy process.
Child wait that process to end.

Client version, wait signal from daemon:
Code:
somechild &
CHILD=$!
cat <<EOF > $$.mydata.ask
MYPID=$$
MYNEED=I/1/34/5
MYANSWERFILE=$$.mydata.answer
SENDSIGNAL2PID=$CHILD
EOF

kill -2 $DAEMONPID
wait $CHILD

# 4  
Old 07-25-2011
thanks for theses completes answers.
Of course, i can modify the c daemon program. (i am coding it)

for kshji solution, thanks for all the code. I can use it. Seems to be a bit heavy for the fs system (embedded system)?

For queue message, it seems to be a good ligth solution.
How can make a message queue between shell script and the process? And does the messages are length dynamic?

my initial idea, but doesn't know if it is possible:
From application make entrie in /proc fs : /proc/mapping
and make a virtual tree.
Code:
procfs_fs_ops mon_dossier {
.list : My_function_lister_folder(string path);
.open : My_function_openfile(string path);
.read : My_function_readfile(string path);
.write : My_function_writefile(string path);
.close : My_function_closefile(string path);
}

is it possible?

all call to a subfolder/subfile acess to the "only function"
My_function_openfile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Communication between different hosts through shell scripts.

1) I have two scripts named as a.sh,b.sh running two different hosts host1 and host2 2) So now how to execute b.sh on host2 from a.sh on host1 3) Also I have few queries regarding the same as I want to execute few commands with sudo and with different user in script b.sh so how this can be... (2 Replies)
Discussion started by: RSC1985
2 Replies

2. UNIX and Linux Applications

emacs gnus-demon not running

My understanding of the gnus-demon is that it should run its handlers each gnus-demon timestep. I have my gnus demon timestep set to the default 60 seconds. I have registered one handler that prints something out every time it is called (and is supposed to update the group buffer). However, the... (0 Replies)
Discussion started by: making
0 Replies

3. Homework & Coursework Questions

Shell program in C

Hi all, I have an assignment from school to write a shell program in linux. the idea is to exercise fork() and execv() functions.. the shell program is supposed to be the master and every command that the user prints will run in a new process. we also need to try running the command in every... (1 Reply)
Discussion started by: r3vive
1 Replies

4. OS X (Apple)

Inter-shell communication

If I open two bash shells and telnet from Shell 2 to a remote server (on the Net), is there a way to direct input from Shell 1 to the telnet shell? The telnet shell is a limited environment with a specific command set. I want to direct commands from Shell 1 and, if possible, put 1-second... (2 Replies)
Discussion started by: xinUoG
2 Replies

5. Shell Programming and Scripting

dilemma what to use c++ or script for demon process

Hello all i need to implement demon that needs to extract data from db load the data to memory and according to this data to perform actions like sending emails or write/update files this action needs to be preformed each 30 min's now i really don't know what to decide or to compile c++... (5 Replies)
Discussion started by: umen
5 Replies

6. Programming

C program using IPC (inter process communication)

i want to write a C chat program that communicates over IPC(inter process communication), that could be run using 2 seperate terminal windows within the same computer. so that wat u type in one terminal window , should appear on the other and vice versa... could some one please help me with the... (2 Replies)
Discussion started by: localp
2 Replies

7. OS X (Apple)

Serial Communication from shell Mac OS X PHP script

Hi again, I spoke with Keyspan and they assured me the USB to Serial device was working if I could use the Screen tool. I asked why I was unable to redirect stdin/stdout to and from the /dev/tty. device and was told there was no reason I shouldn't be able to do so. I have tried: ... (1 Reply)
Discussion started by: cpfogarty
1 Replies

8. Shell Programming and Scripting

help with shell program

I want to print the value of variables a1, a2, a3 in for loop in the following program: a1=this a2=is a3=printed for((i=1;i<4;i++)) do var=a$i #w=`echo $var` e=${var} echo $e done But actually I get a1,a2,a3 as the output not the "this is printed" So the main question is if I... (3 Replies)
Discussion started by: adgarg
3 Replies

9. Shell Programming and Scripting

perl demon how to ?

Hello im kinda new to perl programming in unix i need to make some kind of perl demon that sites and waits to see if there is files in the dir if there is complete file ( not part of it ) , I need to mv it to different dir ok so the easy parts to cp files and perl I know , but how the hell... (1 Reply)
Discussion started by: umen
1 Replies

10. Programming

Communication between a java and c++ program

Hi, I have the following problem. I have 2 programs, a java program and a c++ program. These 2 programs have to communicate with each other in full duplex mode. I want to use pipes for this communication. So when the c++ program pust something on the stdout the java program must be able to read... (4 Replies)
Discussion started by: lmnt22
4 Replies
Login or Register to Ask a Question