can't foreground job (Suspended (tty input))

Michael ODonnell michael.odonnell at comcast.net
Sun Jan 7 16:47:29 EST 2007



> I was actually surpised by the original post, since I've never
> seen that behavior before...

Paul, if you re-read the original post:

   http://mail.gnhlug.org/mailman/private/gnhlug-discuss/2007-January/017578.html

...you'll see that you're not talking about the same behavior
described by the OP.  Despite the Subject: line the OP's examples
never illustrated any inability to foreground his Emacs process.

What the OP did demonstrate was that he was unable to terminate
his (now privileged) Emacs process by sending it SIGTERM.
I'd claim that that's actually the expected behavior but Ben is
understandably puzzled by that in light of the fact that it *is*
still possible to send SIGCONT to that process to foreground it.

I don't have an authoritative explanation for that but it's
probably based on the special relationship the processes in a
"process group" have with the process that's currently group
leader and which owns the controlling tty.  Here's something
from the kernel sources that may be relevant:

 * When SIGCONT is sent, it resumes the process (all threads
 * in the group) from TASK_STOPPED state and also clears
 * any pending/queued stop signals (any of those marked with
 * "stop(*)").  This happens regardless of blocking, catching,
 * or ignoring SIGCONT.  When any stop signal is sent, it
 * clears any pending/queued SIGCONT signals; this happens
 * regardless of blocking, catching, or ignored the stop
 * signal, though (except for SIGSTOP) the default action of
 * stopping the process may happen later or never.

BTW, when you execute a program using sudo it is not the case
that sudo is executing simultaneously with that program.
What happens is that sudo sets up all the necessary
credentials/capabilities and then execs the program in
question, which means that the running instance of sudo is
(effectively) replaced by that program entirely.  Here is a
minimalist but entirely functional sudo.c :

  main( int argc, char **argv )
  {
      setuid( 0 ); setgid( 0 ); execvp( *argv, argv+1 );
  }

Demo:
  cc -o sudo sudo.c ; chown 0.0 sudo ; chmod u+s sudo ; ./sudo id
 


More information about the gnhlug-discuss mailing list