System Variables in C language

System Variables in C language

Post by sce.. » Fri, 21 Jan 2000 04:00:00



Hello Gurus,

I have a C program (A) from which I call another program (B) through
its (B's) API.  I need to have a logic (in A) where I check to see if
I have to call B from A depending on some processing in the program A.

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 am sorry if I haven't explained my problem clearly enough, but any
help is appreciated.

Thanks.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

System Variables in C language

Post by Barry Margoli » Sat, 22 Jan 2000 04:00:00



>I have a C program (A) from which I call another program (B) through
>its (B's) API.  I need to have a logic (in A) where I check to see if
>I have to call B from A depending on some processing in the program A.

>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?

Use a file.  A should check whether the file exists, and only call B if it
doesn't.  If some other process wants to indicate that B shouldn't be
called, it creates the file.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

System Variables in C language

Post by Ken Pizzi » Sat, 22 Jan 2000 04:00:00



>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:
  char junk;
  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
is done.

Now the only piece left is: how does A do its thing?  Well,
immediately after creating the FIFO, A should open it for
writing:
  statfd = open("/some/path/or/other", O_WRONLY);
Then, to indicate that it is done with B, A would simply:
  close(statfd);
Ta da!

                --Ken Pizzini

 
 
 

System Variables in C language

Post by Charlie Gibb » Sat, 22 Jan 2000 04:00:00



(Barry Margolin) writes:

>>I have a C program (A) from which I call another program (B) through
>>its (B's) API.  I need to have a logic (in A) where I check to see if
>>I have to call B from A depending on some processing in the program A.

>>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?

>Use a file.  A should check whether the file exists, and only call B if
>it doesn't.  If some other process wants to indicate that B shouldn't
>be called, it creates the file.

I use this trick myself, often enough to have discovered several ways
it can bite you.  First way: do a kill -9 on the program that should
remove the file before it gets around to doing so.  Second way: create
the file some other way (e.g. by running a program that doesn't know
that it's creating a "magic" file name, or by just doing a cat, vi,
etc.).  Third way: have the system go down (by power failure, kernel
panic, etc.) while the file exists.

Any of these things will ensure that B never gets called again
(at least until you manually remove the file), unless you take
precautionary measures (e.g. remove the file during boot, perhaps
in an rc file).

--

Remove the first period after the "at" sign to reply.

 
 
 

1. Accept-Language CGI environment variable wanted for Apache

Hi,

I have just added an extra language to my Apache server using
content negotiation. Now I want to write a small index.cgi -script
to intercept the users that haven't set a language in their browser.

To see if they haven't I would like to access the value of
Accept-language. Since this isn't one of the standard variables
accessable I wonder if anyone has written a module or made a patch
for Apache. I have looked at the source code and it doesn't seem
impossible, it's just that I'm lousy at C-programming :-)

Thanks in advance
/Hans

2. mo-o-my:

3. Want to change language env variables on Solaris 8

4. SDT-7000 Tape drive! it do not work correctly..

5. c-shell as a command language rather than a programming language

6. A 2.4 box can fake its "personality"

7. Express Learning of languages - Language Bridge

8. Pascal Interpreter using Lex & Yacc

9. Setting variables in a variable array of null variables

10. Programming languages and scripting languages

11. Solaris 8 Multi Language & Web Browsing foreign language sites

12. Which language to program an account administration system ?

13. Worldwide CAD system language corrections