title: ISSUES with SIGCONT and waitpid() in LINUX
body: <p>I'll try to keep it simple. I'm currently replicating a shell for LINUX. I use a linked list structure "job_list" to store all background processes. If a background process is terminated, then it is removed from the list. If a background process is suspended, its status within the list is changed from BACKGROUND to STOPPED. If the process is reawakened (through a SIGCONT signal), then the idea is that the process state inside the list should be changed back to BACKGROUND. </p>
  
  <p>My problem is the following: when I send a SIGSTOP signal to a process, section //1 is executed and its change of state is successfully registered in the list. However, when I reawaken that same process using a SIGCONT signal, WIFCONTINUED(status) will return false, but WIFEXITED(status) will always return true. Consequently, section //3 is executed and the process is removed from the list.</p>
  
  <p>What could be wrong? Thanks in advance.</p>
  
  <pre><code>void sigchld_handler (){
  
  block_SIGCHLD();
  
  
  job *item;
  int l_size = list_size(job_list);
  int i, new_pid, pid_wait, status, info;
  enum status status_res;
  
  for (i = 1; i &lt;= l_size; i++){
  
  
  
      item =  get_item_bypos(job_list, i);
      new_pid = item-&gt;pgid;
      pid_wait = waitpid(new_pid, &amp;status, WUNTRACED | WNOHANG);
  
  
  
      if (WIFSTOPPED(status)){
          //1
          printf("****SUSPENDED\n");
          item-&gt;state = STOPPED;  
  
      }else if (WIFCONTINUED(status)){
          //2
          printf("****CONTINUED\n");
          item-&gt;state = BACKGROUND;
  
      }else if (WIFEXITED(status)){
          //3
          printf("****EXITED\n");
          l_size--;
          i--;
          delete_job(job_list, item); 
  
      }
  }
  
  print_job_list(job_list);
  unblock_SIGCHLD();
  </code></pre>
  
  <p>}   </p>