Re: Suggestions of design (contd.)

From: Kelvin Moss (km_jr_usenet_at_yahoo.com)
Date: 02/18/05


Date: 18 Feb 2005 07:21:30 -0800


Måns Rullgård wrote:
> "Kelvin Moss" <km_jr_usenet@yahoo.com> writes:

> What is the program doing otherwise? If it spends most of the time
> waiting on a socket or similar, you could use select() with a timeout
> to get a chance at doing other things every now and then.

Yes, a call similar to select can help me here.
Well the program is meant for SNMP statistics. So it is something like
this in short --

1. The SNMP subagent creates a shared memory region and semaphore
2. It registers a handler so that it can know the state of shared
memory every second. It needs to flush the shared memory too after it
has read it.
3. If a snmpget request comes then it needs to answer the desired
value.

I am using NetSNMP library (Linux).

So the way we wait for snmpget requests is --

while(1) {
    /* if you use select(), see snmp_select_info() in snmp_api(3) */
    /* Some processing */

        agent_check_and_process(1); /* 0 == don't block */
  }

agent_check_and_process api blocks till an snmpget is encountered or an
alarm condition occurred. I can use the latter to do some processing
from time to time.

> > I know that having statements like printf etc in signal handler is
> > disastrous since it in turn could be calling malloc etc. Is there
any
> > danger which I am overlooking when I grab semaphore and do some
> > processing in the signal handler ?
>
> If you only use functions that are explicitly mentioned as safe to
> call from a signal handler, you'll be fine. I'm not sure about the
> semaphore functions, but the safe functions are the minority out
> there.

Yes.

Thanks for all your inputs. I really appreciate them.



Relevant Pages

  • Re: Inter-processor atomic operationss
    ... difference between the implementation of this hypothetical synchronization ... Need to either always use a keyed event for the wait semaphore ... Don't refer to any memory not in the shared memory region. ... Does the Interlocked API set guarantee inter CPU atomic operations ...
    (microsoft.public.win32.programmer.kernel)
  • Inter Process Communication
    ... Two or several processes can exchange data through this resource. ... The shared memory ID is given as program argument. ... sem_create: creates a semaphore set. ...
    (comp.unix.programmer)
  • Re: suggestion for process shared mutex
    ... Ittay Freiman wrote: ... > did they provide such a feature for shared memory, ... Each process using the semaphore should, ... in that shared region. ...
    (comp.os.linux.development.system)
  • TSP and CreateSemaphore/CreateFileMapping
    ... shared memory & a semephore. ... The other process creates the semaphore and the shared ... Now when I run each of these, all return values from the Win32 APIs indicate ... GetLastError, it returns ERROR_ALREADY_EXISTS. ...
    (microsoft.public.win32.programmer.tapi)