views:

111

answers:

4

Hi all,

I have to implement some mechanism in C on SOLARIS 9 SPARC in order to allow interprocess communication.

In a nutshell, i have to implement a multithread program where the father of the thread once receive a signal, or whatever you want, has to trigger a set of thread that are in charge of encrypting files.

I cannot use some TCP socket solution to communicate with this program.

I was thinking on using system signals (and triggering the process by kill -s SIGNAL PID) or by domain unix socket.

What do you think? Can you suggest me some other solutions?

+3  A: 

other solutions: shared memory segments, pipelining, Unix sockets (hey, they're not TCP :)), ...

Timothy
0 down vote accept Do you have some example or can you pointing to some resources about your suggestions?I mean some basic c example!Thanks a lot!
Kerby82
check out http://en.wikipedia.org/wiki/Inter-process_communication, http://beej.us/guide/bgipc/output/html/multipage/unixsock.html, and http://www.cs.cf.ac.uk/Dave/C/node27.html
Timothy
+1  A: 

If I understand your question, take a look at POSIX message queues, specifically mq_notify(). You can communicate through the message queue and set it up to automatically spawn a thread when a message is received. That thread reads the queue for the filename and whatever and does the encryption.

Duck
A: 

You might want to take a look at named pipes, here is some excellent documentation from Sun, read it.

Anders
A: 

What do you think? Can you suggest me some other solutions?

A signal is a perfectly good solution, and simpler than many. I would probably use that myself. Most of the others involve more changes to the host environment that will outlive the process and/or make it harder to run multiple copies of the system concurrently (because you have to manage distinct filenames, port numbers, shared memory ids etc yourself whereas the OS already tracks PIDs and allows them as a target for kill).

Still, if you want another option, a named pipe is very, very easy to use. In your shell, just "mkfifo xyz" to create a pipe named "xyz" in your current directory. Then you can have the thread you want to signal block reading the pipe, then echo "go boy go" > xyz into the pipe and your control thread will exit the read().

Tony