Conceptual Questions About Processes and Signals

93 views Asked by At

I am studying for my final in systems programming and I have a few questions that I cannot answer.

  1. Say a parent process forks off a child process that creates a large object. Can the child pass this object back to the parent fairly easily using just signals?

  2. A parent process forks off a child process, and the child continues running the same program. Is the best way for the parent to give a data structure to a child that was created before the fork to write to a separate file and give that to the child? (This one I am thinking it is not a good way, because the child will still share some of the parents data, including said data structure)

  3. Let us say you write a program to measure how quick a person's fingers are by trapping SIGINT and then asking them to press Ctrl-C as rapidly as possible. The SIGINT signal handler increments a global counter every time Ctrl-C is typed. After a predefined time it stops and prints the global counter divided by the time used. What is a fundamental problem with this program?

Any help is appreciated.

1

There are 1 answers

1
Clarus On

Some quick thoughts on your questions;

  1. No, signals are not good for transferring data. Signals involve a lot of overhead and are not queued very effectively.
  2. Many methods of IPC are available. The two that are most popular for UNIX are sockets and shared memory (see shm for instance). Sockets are generally better when talking to un-trusted applications. In your example of forking an application pipes would be applicable as well.
  3. As long as you can handle the interrupt much faster than they are coming in you are OK. Probably in the case with your ctrl-c example you could do the same thing using poll and fcntl (on UNIX) and you would be likely to get better precision.