I am working on my own shell and I have a confusion about job management.

I am able to list processes owned by a user and pause any process that its pid is given. However, as stated in title, I need to bring back paused jobs to running state and either background or foreground.

My commands will be like this:

mybg <PID>
myfg <PID>

Now, I just thought getting process names with that pids and use bg/fg with process names. This does not help much.


How do you pause a job? The only way I know is to send it SIGSTOP, which you do from bash with Ctrl-Z for the foreground job.

Being as it is not running after that, it is not the foreground job any more, so your keyboard has no connection to it. The shell is the foreground job, and you have to tell the shell to fg or bg its child.

However, the shell sends the job a SIGCONT to un-stop it. The process does not get these signals directly. Kernel changes the run status for the Pid, and the scheduler ignores the job if it is in Stopped state.

You can also directly kill -STOP %1 or kill -STOP 14193 (job id or pid) and the same for -CONT, in bash.

  • 1
    Ctrl-Z sends a SIGTSTP not a SIGSTOP. And a stopped foreground job is still very much a foreground job, until another job is made the fg one with tcsetpgrp. – mosvy Mar 1 '20 at 18:07
  • Well, this forum is Unix/Linux. IIRC, Solaris did not have a distinct SIGTSTP, and you continued from the keyboard with Ctrl-Q. On Linux, both signals stop the process, but Ctrl-Z has a distinct signal and can be ignored. SIGCONT continues the process, but you can use fg or bg in bash to continue but change the job type. TIL the parent gets a SIGCHLD when the child is stopped, too. – Paul_Pedant Mar 1 '20 at 21:25
  • 2
    Solaris did have a SIGTSTP since its very beginnings. Ctrl-S/Ctrl-Q are a very different thing, completely unrelated (man termios, /IXON). So let me try again -- a stopped foreground job is STILL the foreground job. And the process does get these signals directly -- that's how vim or emacs know when to switch to/from the alternate screen and save/restore the terminal settings. – mosvy Mar 1 '20 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.