>Program A gets called by many processes and if at one point of time
>it is decided that the program B need not be called any longer from A
>then it has to be seen by other processes that start A (some kind of
>System Variable???) after the change takes place...
>What is the best way of doing this?
I presume that you really mean "processes" and not "functions"
(it isn't completely clear from the post that this is the case)?
You'll need to use some IPC mechanism. Shared memory, a
semaphore, or an I/O trick all seem to suggest themselves as
likely candidates. I'll go with a I/O based suggestion, since
it is very portable, and reasonably low cost...
Start out by creating a FIFO:
mknod("/some/path/or/other", S_FIFO|0444, 0);
Then, processes which want to know wheter A is done calling B
can check this by first opening:
statfd = open("/some/path/or/other", O_RDONLY|O_NONBLOCK);
and then querying the status with:
status = read(statfd, &junk, 1);
A status of -1 (errno==EWOULDBLOCK) indicates that A has not
yet indicated that it is done calling B; a status of 0
indicates that it is done. (Note: if you actually want to
_wait_ for A to be done with B, leave off the O_NONBLOCK
on the open() call (or use fcntl() to turn off O_NONBLOCK);
then the read() command will block until A indicates that it
Now the only piece left is: how does A do its thing? Well,
immediately after creating the FIFO, A should open it for
statfd = open("/some/path/or/other", O_WRONLY);
Then, to indicate that it is done with B, A would simply: