Note that there are some explanatory texts on larger screens.

plurals
  1. PORace conditions in my signal handlers? (C)
    primarykey
    data
    text
    <p>I'm working on a shell lab for a Systems course, and I've been having some really weird race condition bugs that I've been trying to solve since Friday night and can't seem to pin down.</p> <p>My current code: <a href="http://buu700.com/tsh" rel="nofollow">http://buu700.com/tsh</a></p> <p>Everything before <code>START OF MY CODE</code> and after <code>END OF MY CODE</code> is provided by the course instructors, so none of that should be the source of the issues.</p> <p>We have a test script as well; here is the output of my current test results: <a href="http://buu700.com/sdriver" rel="nofollow">http://buu700.com/sdriver</a></p> <hr> <pre><code>/***************** * Signal handlers *****************/ /* * sigchld_handler - The kernel sends a SIGCHLD to the shell whenever * a child job terminates (becomes a zombie), or stops because it * received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The * handler reaps all available zombie children, but doesn't wait * for any other currently running children to terminate. */ void sigchld_handler(int sig) { pid_t pid; int status, termsig; struct job_t *job; sigset_t s; sigemptyset(&amp;s); sigaddset(&amp;s, SIGCHLD); sigaddset(&amp;s, SIGINT); sigaddset(&amp;s, SIGTSTP); sigprocmask(SIG_BLOCK, &amp;s, NULL); while ((pid = waitpid(-1, &amp;status, WNOHANG | WUNTRACED)) &gt; 0) { if (WIFEXITED(status)) { deletejob(job_list, pid); } if ((termsig = WTERMSIG(status))) { deletejob(job_list, pid); safe_printf("Job [%i] (%i) %s by signal %i\n", pid2jid(pid), pid, "terminated", termsig); } if (WIFSTOPPED(status)) { job = getjobpid(job_list, pid); job-&gt;state = ST; safe_printf("Job [%i] (%i) %s by signal %i\n", pid2jid(pid), pid, "stopped", SIGTSTP); } } if (errno != ECHILD) unix_error("waitpid error"); sigprocmask(SIG_UNBLOCK, &amp;s, NULL); return; } /* * sigint_handler - The kernel sends a SIGINT to the shell whenver the * user types ctrl-c at the keyboard. Catch it and send it along * to the foreground job. */ void sigint_handler(int sig) { sigset_t s; sigemptyset(&amp;s); sigaddset(&amp;s, SIGCHLD); sigaddset(&amp;s, SIGINT); sigaddset(&amp;s, SIGTSTP); sigprocmask(SIG_BLOCK, &amp;s, NULL); kill(-1, sig); sigprocmask(SIG_UNBLOCK, &amp;s, NULL); return; } /* * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever * the user types ctrl-z at the keyboard. Catch it and suspend the * foreground job by sending it a SIGTSTP. */ void sigtstp_handler(int sig) { sigset_t s; sigemptyset(&amp;s); sigaddset(&amp;s, SIGCHLD); sigaddset(&amp;s, SIGINT); sigaddset(&amp;s, SIGTSTP); sigprocmask(SIG_BLOCK, &amp;s, NULL); kill(-1, sig); sigprocmask(SIG_UNBLOCK, &amp;s, NULL); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload