开发者

Interprocess communication on UNIX

I have to implement some mechanism in C on SOLARIS 9 SPARC in order to allow interprocess communica开发者_开发百科tion.

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?


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜