sigusr woes

sigusr woes

Post by Pat For » Fri, 27 Jun 2003 03:35:06



Hi All;
 I have 3 simple programs 2 are pretty much the same record their pid in a
file set up a sigusr1 handler that only does a count++; then return. After
10  signals it printfs "i got 10 signals" and dies.
The third program ( int-gen) sets up a itimer for ~100Hz, opens the file
that contains the pids of the other 2 program, then sets up a sigalarm
handler that alternates sending a sigusr to the other 2 programs and counts
the number of signals sent to each program.

 The problem is that I'm sending ~50 signals to each to get 10 entries to
the sighandler. the code follows, I'm sure its just a bonehead move but no
one here has found the problem

Thanks Pat

;;int-gen.c
void alarmhandler (int signum);

int sampleBlk, chanCnt, numBytes;
volatile int refcnt=0, logcnt=0, count = 0;
pid_t refpid, logpid;

char buffer[200];
int
main (int argc, char *argv[])
{
 char refpidfile[]="/var/ref.pid";
 char logpidfile[]="/var/logic.pid";
 static FILE *refpidf, *logpidf;
 struct itimerval itimer;
 sigset_t blockset, pending;
 int pendingcount;

 if (signal (SIGALRM, &alarmhandler) == SIG_ERR)
    {
  printf ("Couldn't register signal handler for SIGALRM.\n");
 }

 sigemptyset (&blockset);
 sigaddset (&blockset, SIGINT);

 itimer.it_interval.tv_usec = 500;  // values under 1000 ( 100Hz ) dont do
any better then 100Hz
 itimer.it_interval.tv_sec = 0;
 itimer.it_value.tv_usec = 0;
 itimer.it_value.tv_sec = 1;
  // Check Source file for existence
 refpidf = fopen (refpidfile, "r"); // Open source read-only
 if (refpidf == NULL)
    {
  printf (" \n couldn't open input file%.20s\n", refpidfile);
  exit (-1);
    }
    logpidf = fopen (logpidfile, "r"); // Open source read-only
  // Check Source file for existence
 if (logpidf == NULL)
    {
  printf (" \n couldn't open input file%.20s\n", logpidfile);
  exit (-1);
    }
   fread (&refpid,1,sizeof (pid_t),refpidf);
   fread (&logpid,1,sizeof (pid_t),logpidf);
   printf("\n logic pid is %d and ref is %d",logpid,refpid);

  while (count <= 15)
    {

      sigprocmask (SIG_BLOCK, &blockset, NULL);
      setitimer (ITIMER_REAL, &itimer, NULL);
      fgets (buffer, sizeof (buffer), stdin);
      printf ("Input: %s", buffer);

      /* Process pending signals. */

      sigpending (&pending);
      pendingcount = 0;
      if (sigismember (&pending, SIGINT))
     pendingcount++;
      if (sigismember (&pending, SIGTERM))
     pendingcount++;
      if (pendingcount)
   {
     printf ("There are %d signals pending.\n", pendingcount);
   }

      /* Deliver them. */

      sigprocmask (SIG_UNBLOCK, &blockset, NULL);

      /* Exit if requested. */

      if (strcmp (buffer, "exit\n") == 0)
   {
     raise (SIGKILL);
   }

    }
    printf("\n the # of message sent was %d with ref getting %d and logic %d
\n", count, refcnt, logcnt);
  return 0;

Quote:}

void
alarmhandler (int signum)
{
 int killstat;
 count++;
 if (count%2)
 {
  printf("\n logic message");
  killstat=kill(logpid, SIGUSR1);
  if (killstat == -1)
   printf("\n Unable to signal Logic %s", strerror(errno));
  else
   logcnt++;
 }
 else
 {
  printf("\n refference message");
  killstat=kill(refpid, SIGUSR1);
  if (killstat == -1)
  {
   printf("\n Unable to signal Refference %s", strerror(errno));
   printf("\n the # of message sent was %d with ref getting %d and logic %d
\n", count, refcnt, logcnt);
   exit (-1);
  }
  else
   refcnt++;
 }

Quote:}

;; end of int-gen

;; start of int- logic or ref ( both are the same )
void sigusr_hndlr(int sig);
int volatile i=0;
int volatile count=0;
scramnetType *data_ptr;
char buffer[200];

int main (void)
{
 static FILE *pidf;  /* listing file */
 pid_t mypid;
 char pidfile[]="/var/logic.pid";
 int pendingcount;
 sigset_t blockset, pending;
 if( sp_scram_init( 0 ) < 0 )
    {
        printf( "Error initializing SCRAMNet\n" );
        return( -1 );
    }
 data_ptr=(scramnetType *) get_base_mem ();
// install the signal handler code
 if (signal (SIGUSR1, &sigusr_hndlr) == SIG_ERR)
    {
      printf ("Couldn't register signal handler for SIGUSR1.\n");
    }
    sigemptyset (&blockset);
    sigaddset (&blockset, SIGINT);
// dump the pid to a file at a known location
     pidf = fopen (pidfile, "wb");
    if (pidf == NULL)
    {
      printf (" \n FileNot opened %.20s", pidfile);
      return -1;
    }
    mypid=getpid();
    printf("\n my pid is %d",mypid);
    fwrite (&mypid, sizeof (pid_t), 1,pidf );
    fclose(pidf);
// fclose forces the write of the pid.

    printf( "\nWaiting for sigusr1 count is %d\n",count);
 printf( "\n");

   while (count <= 9)
   {
      sigprocmask (SIG_BLOCK, &blockset, NULL);
      sigpending (&pending);
       pendingcount = 0;
       if (sigismember (&pending, SIGINT))
      pendingcount++;
       if (sigismember (&pending, SIGTERM))
      pendingcount++;
       if (pendingcount)
     {
       printf ("There are %d signals pending.\n", pendingcount);
     }
       sigprocmask (SIG_UNBLOCK, &blockset, NULL);
   }   // end of while loop
 printf("\nInt-logic got sigusr1'd count %d \n",count);

Quote:}

void sigusr_hndlr(int sig)
{
    //*signal(SIGUSR1, sigusr_hndlr);
    printf("#\n");
    count++;
Quote:}

 
 
 

sigusr woes

Post by Kasper Dupon » Fri, 27 Jun 2003 05:47:19



> Hi All;
>  I have 3 simple programs 2 are pretty much the same record their pid in a
> file set up a sigusr1 handler that only does a count++; then return. After
> 10  signals it printfs "i got 10 signals" and dies.
> The third program ( int-gen) sets up a itimer for ~100Hz, opens the file
> that contains the pids of the other 2 program, then sets up a sigalarm
> handler that alternates sending a sigusr to the other 2 programs and counts
> the number of signals sent to each program.

>  The problem is that I'm sending ~50 signals to each to get 10 entries to
> the sighandler. the code follows, I'm sure its just a bonehead move but no
> one here has found the problem

Could it be, that you are sending signals too fast? If the same signal is
delivered more than once before the handler is actually executed, it is
only executed once. I didn't read all the code carefully, but I did spot
a single line that is a litle odd:

Quote:

>  itimer.it_interval.tv_usec = 500;  // values under 1000 ( 100Hz ) dont do
> any better then 100Hz

It doesn't look like the numbers here actually match.

--
Kasper Dupont -- der bruger for meget tid p? usenet.

It is NOT portable (Linus Benedict Torvalds 1991)

 
 
 

sigusr woes

Post by Pat For » Fri, 27 Jun 2003 22:19:15




> >  The problem is that I'm sending ~50 signals to each to get 10 entries
to
> > the sighandler. the code follows, I'm sure its just a bonehead move but
no
> > one here has found the problem

> Could it be, that you are sending signals too fast? If the same signal is
> delivered more than once before the handler is actually executed, it is
> only executed once. I didn't read all the code carefully, but I did spot
> a single line that is a litle odd:

> >  itimer.it_interval.tv_usec = 500;  // values under 1000 ( 100Hz ) dont
do
> > any better then 100Hz

 I was playing with different numbers, guess I just have to play more.

Quote:

> It doesn't look like the numbers here actually match.

 What I'm trying to do is get an interrupt from a dual port memory card
(scramnet) and feed it to one of two programs. I know what I'd do in QNX but
there doesn't seem to be high speed proxy on linux.

 On the card I'm using each memory location can generate an interrupt when
it is writen to, so I have  made mailboxes for two processes, that has to
pass alot of messages back and forth. The processes may or may not be on the
same machine. I'm on a Athalon 1900 with 512Mb ram so machine speed
shouldn't be an issue.

 An ideas on a faster messaging method then signals?

- Show quoted text -

> --
> Kasper Dupont -- der bruger for meget tid p? usenet.

> It is NOT portable (Linus Benedict Torvalds 1991)

 
 
 

1. CD-RW mounting woes in Mandrake 7.0 woe oh woe oh woe!

I hate to ask the often answered, but I have a TDK VeloCD CD-RW in my PII
233 machine installed as a master on the secondary IDE. I'm running
Mandrake-linux 7.0, and of course I get the bad link problem. I have run the
fix suggested on Mandrake's Web-page, but I can't figure a way to make the
fix either permenant or automatic. The fix (in case you haven't seen it is
to run "cdrecord -scanbus" to check for the presence of a working CD-RW,
then to type "cd /dev && rm cdrom && ln -s scd0 cdrom" in a terminal) This
fix works but there's got to be a better way...any thoughts.

2. gcc -O2 vs gcc -Os performance

3. XF86 Config set-up woes & woes & woes

4. weirdness

5. net-2 woes (was upgrade woes)

6. Kmail account polling interval

7. RedHat 5.2 to 2.2.4 Woes

8. KDE 3.1 killed my eth0

9. PB 3400 install woes: Mount failure (no such device)

10. Wal-Mart's NT woes (fwd)

11. ***HELP - Installation woes...

12. Real Audio woes

13. PCMCIA woes: Xircom card