Kerby82
Kerby82

Reputation: 5146

Interprocess communication on UNIX

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?

Upvotes: 1

Views: 809

Answers (3)

Tony Delroy
Tony Delroy

Reputation: 106068

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().

Upvotes: 2

Duck
Duck

Reputation: 27542

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.

Upvotes: 0

Timothy
Timothy

Reputation: 4650

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

Upvotes: 3

Related Questions