Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I’ve grown really accustomed to the BSD status char, ^T, since I first started using it back at university during the 80s. It didn’t originate with BSD, but came from even older operating systems. It still works on modern BSD systems, too, including Darwin. This is an example on MacOS, where I hit ^T three times inside grep before I hit ^D:

darwin% stty all
speed 38400 baud; 93 rows; 124 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -iutf8
        -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
        -dtrflow -mdmbuf
discard dsusp   eof     eol     eol2    erase   intr    kill    lnext   
^O      ^Y      ^D      <undef> <undef> ^H      ^C      ^U      ^V      
min     quit    reprint start   status  stop    susp    time    werase  
1       ^\      ^R      ^Q      ^T      ^S      ^Z      0       ^W      

darwin% grep foo
load: 0.05  cmd: grep 7227 waiting 0.00u 0.00s
load: 0.05  cmd: grep 7227 waiting 0.00u 0.00s
load: 0.05  cmd: grep 7227 waiting 0.00u 0.00s

And this is the same thing on OpenBSD, where it is even better, since I get the wait channel

openbsd% stty all
speed 38400 baud; 93 rows; 124 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc -xcase
iflags: -istrip icrnl -inlcr -igncr -iuclc ixon -ixoff ixany imaxbel
        -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl -onocr -onlret -olcuc oxtabs -onoeot
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -mdmbuf
discard dsusp   eof     eol     eol2    erase   intr    kill    lnext   
^O      ^Y      ^D      <undef> <undef> ^H      ^C      ^U      ^V      
min     quit    reprint start   status  stop    susp    time    werase  
1       ^\      ^R      ^Q      ^T      ^S      ^Z      0       ^W      

openbsd% grep foo
load: 0.67  cmd: grep 3759 [ttyin] 0.00u 0.02s 0% 190k
load: 0.67  cmd: grep 3759 [ttyin] 0.00u 0.02s 0% 190k
load: 0.67  cmd: grep 3759 [ttyin] 0.00u 0.02s 0% 190k

As you see it is really great for knowing what a program is doing when it seems to have gone south. Notice how on OpenBSD it shows not just the wait channel, but the process memory and CPU percentage.

My question is: is there any way to make this work on Linux?

However, it doesn’t work on Linux, so is there any way to make it work? Has anybody already done this? There seems to be enough room for it in the c_ch[] array, since Linux appears to have a lot of padding there with unused slots.

Here is the Linux /usr/include/bits/termios.h file:

#define NCCS 32
struct termios
  {
    tcflag_t c_iflag;           /* input mode flags */
    tcflag_t c_oflag;           /* output mode flags */
    tcflag_t c_cflag;           /* control mode flags */
    tcflag_t c_lflag;           /* local mode flags */
    cc_t c_line;                        /* line discipline */
    cc_t c_cc[NCCS];            /* control characters */
    speed_t c_ispeed;           /* input speed */
    speed_t c_ospeed;           /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
  };

/* c_cc characters */
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16

It looks like there are 17 out of 32 slots in the Linux c_cc[] array defined. Can those truly be used? I wonder why they are not marked as spares.

On OpenBSD, /use/include/sys/termios.h has these in it:

/*
 * Special Control Characters
 *
 * Index into c_cc[] character array.
 *
 *      Name         Subscript  Enabled by
 */
#define VEOF            0       /* ICANON */
#define VEOL            1       /* ICANON */
#if __BSD_VISIBLE
#define VEOL2           2       /* ICANON */
#endif
#define VERASE          3       /* ICANON */
#if __BSD_VISIBLE
#define VWERASE         4       /* ICANON */
#endif
#define VKILL           5       /* ICANON */
#if __BSD_VISIBLE
#define VREPRINT        6       /* ICANON */
#endif
/*                      7          spare 1 */
#define VINTR           8       /* ISIG */
#define VQUIT           9       /* ISIG */
#define VSUSP           10      /* ISIG */
#if __BSD_VISIBLE
#define VDSUSP          11      /* ISIG */
#endif
#define VSTART          12      /* IXON, IXOFF */
#define VSTOP           13      /* IXON, IXOFF */
#if __BSD_VISIBLE
#define VLNEXT          14      /* IEXTEN */
#define VDISCARD        15      /* IEXTEN */
#endif
#define VMIN            16      /* !ICANON */
#define VTIME           17      /* !ICANON */
#if __BSD_VISIBLE
#define VSTATUS         18      /* ICANON */
/*                      19         spare 2 */
#endif
#define NCCS            20

I wonder why there appear to be so many spares under Darwin, given that there are only two spares under OpenBSD. But even so, it looks like this should be possible, so I cannot imagine no one has ever hacked up their kernel (as stty(1), etc) to support it.

Any pointers to working implementations before I go getting my hands dirty?

share|improve this question
    
You know, I get the distinct impression that this StackExchange is not for superusers and other power users after all. Doesn’t anybody hack on their own kernels anymore? How sad!! –  tchrist Aug 25 '11 at 0:49
    
For the most part sysadmins work at a slightly higher level than that these days (whether that is bad or good is a point of view thing, IMO). –  Slartibartfast Aug 25 '11 at 2:35
1  
You base that impression upon the fact that after a mere three hours, in the middle of the night on two continents, no-one touched this question? –  JdeBP Aug 25 '11 at 7:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.