title: poll() catch thread return value
body: <p>I have a poll() loop with a small socket communication, I want to start an other program by system() or exec() and I need the the return value of the system()/exec() but I don't want to stop the main loop while the child process is running so I thought I start it in a thread but I am not sure how to set up the pollfd to catch the thread when it is done, I am using c/c++</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/un.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;poll.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;thread&gt;
  #include &lt;future&gt;
  
  
  #define SOCKET_NAME "/tmp/9Lq7BNBnBycd6nxy.socket"
  
  int runProgram(const std::string &amp;programName, const std::string &amp;fileName) {
      return system((programName + " " + fileName).c_str());
  }
  
  int main(int argc, char *argv[]) {
      struct sockaddr_un server;
      int sock;
      char buf[1024];
      unlink(SOCKET_NAME);
  
      sock = socket(AF_UNIX, SOCK_STREAM, 0);
      if (sock == -1){
              perror("socket");
              exit(EXIT_FAILURE);
      }
      memset(&amp;server, 0, sizeof(struct sockaddr_un));
  
      server.sun_family = AF_UNIX;
      strncpy(server.sun_path, SOCKET_NAME, sizeof(server.sun_path) - 1);
  
      if (bind(sock, (struct sockaddr *) &amp;server, sizeof(struct sockaddr_un)) &lt; 0) {
              perror("bind");
              exit(EXIT_FAILURE);
      }
  
      if (listen(sock, 3) &lt; -1) {
              perror("listen");
              exit(EXIT_FAILURE);
      }
  
      struct pollfd fds[2];
      fds[0].fd = sock;
      fds[0].events = POLLIN;
  
      std::future&lt;int&gt; ret = std::async(&amp;runProgram, "cat", "test.txt");
  
      while (true) {
              poll(fds, 2, -1);
              if(fds[0].revents &amp; POLLIN) {
                      int new_sd = accept(fds[0].fd, NULL, NULL);
                      if (new_sd &lt; 0) {
                              perror("accept");
                      }
                      fds[1].fd = new_sd;
              }
              if (fds[0].revents &amp; POLLIN) {
                      int rv = recv(fds[1].fd, buf, 1024, 0);
                      if (rv &lt; 0)
                              perror("recv");
                      else if (rv == 0) {
                              printf("disconnet\n");
                              close(fds[1].fd);
                      } else {
                              printf("%s\n", buf);
                              send(fds[1].fd, buf, 1024, 0);
                      }
                       memset(buf, 0, 1024);
  
              }
      }
      close(sock);
      return(EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>So I want to add one more to the pollfd (fds[ret.get()]) and get a POLLIN on fds[2] when my thread is done and I can get the return value (ret.get()), here I used an exaple command cat but in my final code the command would need mach more time so I cant wait for that to finish</p>