Enabling job monitoring in a ksh93 script breaks job control

Solution Verified - Updated -


Consider following script:

#!/bin/ksh -p
set -m
/bin/echo hello world
exit 0  # The echo command must be followed by a line in order to reproduce the issue

Note that without a line after /bin/echo statement the incorrect behaviour will not reproduce. At least one (possibly blank) line must follow /bin/echo.

Once /bin/echo completes, ksh93 tries to set the foreground process group of the controlling tty (which is assumed to be open on stderr). However, neither does it apply its pgid, nor does it ignore SIGTTOU, hence when it executes

ioctl(2, TIOCSPGRP, 0)

it receives SIGTTOU.

This ioctl is restarted (SA_RESTART), resulting in another TTOU signal and infinite loop.

Correct setting of SIGTTOU to SIG_IGN and job.mypid to the shell's pid are performed only if ksh93 starts as an interactive shell.

Use of fd 2 for tty handling is in itself incorrect. It is possible during an interactive ksh sessions (and indeed within a script), to close or redirect fd 2 using exec. From that point on, job control in this interactive shell is effectively broken regardless of whether fd 2 is set
back to /dev/tty or not.


Red Hat Enterprise Linux (RHEL) 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content