title: Poll() to monitor a pin on BeagleBone Black. Continuous output even though pin not connected.
body: <p>I want to trigger an event whenever there is a rising edge on one of the pins of Beaglebone Black. 
  Problem is, even though I havent connected that pin to anything, the output just goes on printing, interrupt occured, interrupt occured. I came across question <a href="https://stackoverflow.com/questions/11831590/interrupts-in-beaglebone">Interrupts in Beaglebone</a> 
  on stackoverflow and tried to follow the steps. There was a link to a <a href="https://developer.ridgerun.com/wiki/index.php/Gpio-int-test.c" rel="nofollow noreferrer">Program</a> which implements the functionality. 
  I read about poll() and I made slight changes in the program since I want to monitor just one pin. The changed code is : </p>
  
  <pre><code>int main(int argc, char **argv, char **envp)
  {
  struct pollfd fdset[1];  // fdset[2] changed to fdset[1] since I will monitor just 1 pin
  int nfds = 1;            // nfds changed from 2 to 1
  int gpio_fd, timeout, rc;
  char *buf[MAX_BUF];
  unsigned int gpio;
  int len;
  
  
  
  if (argc &lt; 2) {
      printf("Usage: gpio-int &lt;gpio-pin&gt;\n\n");
      printf("Waits for a change in the GPIO pin voltage level or input on stdin\n");
      exit(-1);
  }
  
  gpio = atoi(argv[1]);
  
  gpio_export(gpio);
  gpio_set_dir(gpio, 0);
  gpio_set_edge(gpio, "rising");
  gpio_fd = gpio_fd_open(gpio);
  
  timeout = POLL_TIMEOUT;
  
  while (1) {
      memset((void*)fdset, 0, sizeof(fdset));
  
      fdset[0].fd = gpio_fd;                 // This is the pin to be monitored
      fdset[0].events = POLLIN;
  
      //fdset[1].fd = gpio_fd;               // commented since I do not need this
      //fdset[1].events = POLLPRI;
  
      rc = poll(fdset, nfds, timeout);      
  
      if (rc &lt; 0) {
          printf("\npoll() failed!\n");
          return -1;
      }
  
      if (rc == 0) {
          printf(".");
      }
  
      if (fdset[0].revents &amp; POLLIN) {
          len = read(fdset[0].fd, buf, MAX_BUF);
          printf("\npoll() GPIO %d interrupt occurred\n", gpio);
      }
  
              // ****Commented block****
      //if (fdset[0].revents &amp; POLLIN) {
      //  (void)read(fdset[0].fd, buf, 1);
      //  printf("\npoll() stdin read 0x%2.2X\n", (unsigned int) buf[0]);
      //}
  
      fflush(stdout);
  }
  
  gpio_fd_close(gpio_fd);
  return 0;
  }
  </code></pre>
  
  <p>Running Angstrom on Beaglebone black. </p>