[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ^Z signal



> (^Z usually generates a SIGTSTP signal, which the shell turns
> into a SIGSTOP sent to the currently running process - at least,
> that's my understanding of it; i've never written the code myself)

A job control shell puts each pipeline that it runs into a separate
process group, then makes that process group `own' the terminal (a
simplification for the purposes of discussion ;-).  This means that
keyboard-generated signals like SIGINT, SIGQUIT, and SIGTSTP go to the
process group that currently owns the terminal, not the shell.  The
shell notices that a pgrp is stopped by the return value from
wait3/wait4/waitpid.  Job control works on the process group/pipeline
level rather than an individual process, though the vast majority
of process groups that a shell deals with consist of a single process.

> what primitives are actually necessary to allow an implementation 
> of job control within es ?

The first step is to put each pipeline forked off into a separate
process group, use tcsetpgrp to give the terminal to that process
group while the pipeline executes, wait for a pipeline with WNOHANG,
and understand what to do when a process stops and
WIFSTOPPED(status) == 1.  The rest is just data structures, signal
handling, synchronization, and bookkeeping. 

Chet

--
       ``He is asleep.  Though his mettle was sorely tried, He
         lived, and when he lost his angel, died.  It happened
         calmly, on its own.  The way night comes when day is done.''
Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu