title: how to immediately wake up the daemon by sending him a SIGUSR1 signal
body: <p>I wrote a program deamon which copy files with one folder to another .I have to implement SIGUSR1 which  immediately wake up the daemon by sending him a SIGUSR1 signal. I do not know what I did wrong ,I  use command  kill -SIGUSR1 ,maybe wrong command?.Somebody know what is wrong with this code ?I did not have any warning after compiled this program,but just nothing happend </p>
  
  <pre><code> #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;syslog.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;dirent.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;signal.h&gt;
  
  #define _XOPEN_SOURCE ;
  
  int recursion = 0; //1 if enabled, otherwise 0
  int sleepTime = 300;
  int fileLimit = 0;
  int signaL = 0;
  int exitSignal = 0;
  int buffer = 1000;
  
  //Returns 0 if arguments are correct otherwise returns 1
  int readArguments(int number, char **argv, char *source, char *goal);
  int checkFileType(struct stat file);
  int copy(char *source, char *target, mode_t mask);
  int copy_map(char *source, char *target, struct stat *Source);
  void syncCopy(char *source, char *target);
  void syncRemove(char *source, char *target);
  
  
  void my_handler(int sig)
  {
      syslog(LOG_INFO, "Daemon received signal SIGUSR1\n");
      signaL = 1;
  }
  
  void exitFunction(int sig)
  {
      syslog(LOG_INFO, "Daemon received signal SIGUSR2\n");
      exitSignal = 1;
  }
  int main(int argc, char **argv)
  {
      //char tables for paths
      char source[500], goal[500];
      struct stat Source, Goal;
      struct sigaction my_action, old_action;
  
      //checking and reading arguments
      if (readArguments(argc, argv, source, goal) == 1)
          exit(-1);
  
      //checking paths
  
      //checking  if argv[1] and argv[2] are existing paths
      if (lstat(source, &amp;Source) != 0 || lstat(goal, &amp;Goal) != 0) //bad result
      {
          printf("One of the paths or both dont exist\n");
          exit(-1);
      }
  
      if (checkFileType(Source) != 0)
      {
          printf("Source path is not path to folder");
          exit(-1);
      }
  
      if (checkFileType(Goal) != 0)
      {
          printf("Goal path is not path to folder");
          exit(-1);
      }
  
      //forking the parent process
      pid_t pid;
      // Fork off the parent process  and create new
      pid = fork();
      //if failure
      if (pid &lt; 0)
      {
          exit(-1);
      }
      // if it is native process
      else if (pid &gt; 0)
      {
          return 0;
      }
      //if pid==0 then it is childs process
  
      //now we have to umask in order to write to any files(for exmaple logs)
  
      umask(0);
      openlog("logFile", LOG_PID, LOG_DAEMON);
      syslog(LOG_INFO, "Deamon has just started running\n");
  
      pid_t sid = setsid();
      if (sid &lt; 0)
      {
          syslog(LOG_ERR, "Error with session opening\n");
          exit(-1);
      }
  
      //SIGNAL SIGUSR1
      my_action.sa_handler = my_handler;
      sigfillset(&amp;my_action.sa_mask);
      my_action.sa_flags = 0;
      if (sigaction(SIGUSR1, &amp;my_action, &amp;old_action) &lt; 0)
      {
          syslog(LOG_ERR, "Error with the use of  SIGUSR1 signal\n");
          exit(-1);
      }
  
      //SIGNAL SIGUSR2 for exiting daemon
      my_action.sa_handler = exitFunction;
      sigfillset(&amp;my_action.sa_mask);
      my_action.sa_flags = 0;
      if (sigaction(SIGUSR2, &amp;my_action, &amp;old_action) &lt; 0)
      {
          syslog(LOG_ERR, "Error with the use of  SIGUSR2 signal\n");
          exit(-1);
      }
  
      while (!exitSignal)
      {
          sleep(sleepTime);
          switch (signaL)
          {
          case 0:
              syslog(LOG_INFO, "Demon started working after %ds\n", sleepTime);
              break;
  
          case 1:
          {
              syslog(LOG_INFO, "Demon started working after SIGUSR1 signal\n");
              signaL = 0; //Need to reeset signaL
              break;
          }
          }
  
          syncCopy(source, goal);
          syncRemove(source, goal);
          syslog(LOG_INFO, "Demon has just  gone to sleep");
      }
  
      //at the end of program we need to close log using
      syslog(LOG_INFO, "Demon has stopped\n");
      closelog();
  
      return 0;
  }
  </code></pre>