title: A Linux Daemon and the STDIN/STDOUT
body: <p>I am working on a linux daemon and having some issues with the stdin/stdout. Normally because of the nature of a daemon you do not have any stdin or stdout. However, I do have a function in my daemon that is called when the daemon runs for the first time to specify different parameters that are required for the daemon to run successfully. When this function is called the terminal becomes so sluggish that I have to launch a seperate shell and kill the daemon with top to get a responsive prompt back. Now I suspect that this has something to do with the forking process closing the stdin/stdout but I am not quite sure how I could work around this. If you guys could shed some light on the situation that would be most appreciated. Thanks.</p>
  
  <p>Edit:</p>
  
  <pre><code>int main(argc, char *argv[]) {
  
  /* setup signal handling */
  
  /* check command line arguments */
  
  pid_t pid, sid;
  
  pid = fork();
  
  if (pid &lt; 0) {
  exit(EXIT_FAILURE);
  }
  
  if(pid &gt; 0){
  exit(EXIT_SUCCESS);
  }
  
  sid = setsid();
  
  if(sid &lt; 0) {
  exit(EXIT_FAILURE);
  }
  
  umask(027);
  
  /* set syslogging */
  
  /* do some logic to determine wether we are running the daemon for the first time and if we are call the one time function which uses fgets() to recieve some input */
  
  while(1) {
  
  /* do required work */
  
  }
  
  /* do some clean up procedures and exit */
  
  return 0;
  }
  </code></pre>
  
  <p>You guys mention using a config file. This is is exactly what I do to store the parameters recieved via input. However I still initially need to get these from the user via the stdin. The logic for determining whether we are running for the first time is based off of the existence of the config file.  </p>