home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / infoguide / advanced / unix / unix-faq-part4 < prev    next >
Text File  |  1997-12-01  |  26KB  |  636 lines

  1. Archive-name: unix-faq/faq/part4
  2. Version: $Id: part4,v 2.4 1994/01/14 14:58:06 tmatimar Exp $
  3.  
  4. These seven articles contain the answers to some Frequently Asked
  5. Questions often seen in comp.unix.questions and comp.unix.shell.
  6. Please don't ask these questions again, they've been answered plenty
  7. of times already - and please don't flame someone just because they may
  8. not have read this particular posting.  Thank you.
  9.  
  10. This collection of documents is Copyright (c) 1994, Ted Timar.
  11. All rights reserved.  Permission to distribute the collection is
  12. hereby granted providing that distribution is electronic, no money
  13. is involved, reasonable attempts are made to use the latest version
  14. and all credits and this copyright notice are maintained.
  15. Other requests for distribution will be considered.
  16.  
  17. All information here has been contributed with good intentions, but
  18. none of it is guaranteed either by the contributors or myself to be
  19. accurate.  The users of this information take all responsibility for
  20. any damage that may occur.
  21.  
  22. Many FAQs, including this one, are available on the archive site
  23. rtfm.mit.edu in the directory pub/usenet/news.answers.
  24. The name under which a FAQ is archived appears in the "Archive-Name:"
  25. line at the top of the article.  This FAQ is archived as
  26. "unix-faq/faq/part[1-7]".
  27.  
  28. These articles are divided approximately as follows:
  29.  
  30.       1.*) General questions.
  31.       2.*) Relatively basic questions, likely to be asked by beginners.
  32.       3.*) Intermediate questions.
  33.       4.*) Advanced questions, likely to be asked by people who thought
  34.        they already knew all of the answers.
  35.       5.*) Questions pertaining to the various shells, and the differences.
  36.       6.*) An overview of Unix variants.
  37.       7.*) An comparison of configuration management systems (RCS, SCCS).
  38.  
  39. This article includes answers to:
  40.  
  41.       4.1)  How do I read characters from a terminal without requiring the user
  42.               to hit RETURN?
  43.       4.2)  How do I check to see if there are characters to be read without
  44.               actually reading?
  45.       4.3)  How do I find the name of an open file?
  46.       4.4)  How can an executing program determine its own pathname?
  47.       4.5)  How do I use popen() to open a process for reading AND writing?
  48.       4.6)  How do I sleep() in a C program for less than one second?
  49.       4.7)  How can I get setuid shell scripts to work?
  50.       4.8)  How can I find out which user or process has a file open or is using
  51.             a particular file system (so that I can unmount it?)
  52.       4.9)  How do I keep track of people who are fingering me?
  53.       4.10) Is it possible to reconnect a process to a terminal after it has
  54.             been disconnected, e.g. after starting a program in the background
  55.             and logging out?
  56.       4.11) Is it possible to "spy" on a terminal, displaying the output
  57.             that's appearing on it on another terminal?
  58.  
  59. If you're looking for the answer to, say, question 4.5, and want to skip
  60. everything else, you can search ahead for the regular expression "^4.5)".
  61.  
  62. While these are all legitimate questions, they seem to crop up in
  63. comp.unix.questions or comp.unix.shell on an annual basis, usually
  64. followed by plenty of replies (only some of which are correct) and then
  65. a period of griping about how the same questions keep coming up.  You
  66. may also like to read the monthly article "Answers to Frequently Asked
  67. Questions" in the newsgroup "news.announce.newusers", which will tell
  68. you what "UNIX" stands for.
  69.  
  70. With the variety of Unix systems in the world, it's hard to guarantee
  71. that these answers will work everywhere.  Read your local manual pages
  72. before trying anything suggested here.  If you have suggestions or
  73. corrections for any of these answers, please send them to to
  74. tmatimar@empress.com.
  75.  
  76. ----------------------------------------------------------------------
  77.  
  78. Subject: How do I read characters ... without requiring the user to hit RETURN?
  79. Date: Thu Mar 18 17:16:55 EST 1993
  80.  
  81. 4.1)  How do I read characters from a terminal without requiring the user
  82.       to hit RETURN?
  83.  
  84.       Check out cbreak mode in BSD, ~ICANON mode in SysV.
  85.  
  86.       If you don't want to tackle setting the terminal parameters
  87.       yourself (using the "ioctl(2)" system call) you can let the stty
  88.       program do the work - but this is slow and inefficient, and you
  89.       should change the code to do it right some time:
  90.  
  91.       #include <stdio.h>
  92.       main()
  93.       {
  94.         int c;
  95.  
  96.         printf("Hit any character to continue\n");
  97.         /*
  98.          * ioctl() would be better here; only lazy
  99.          * programmers do it this way:
  100.          */
  101.         system("/bin/stty cbreak");        /* or "stty raw" */
  102.         c = getchar();
  103.         system("/bin/stty -cbreak");
  104.         printf("Thank you for typing %c.\n", c);
  105.  
  106.         exit(0);
  107.       }
  108.  
  109.       Several people have sent me various more correct solutions to
  110.       this problem.  I'm sorry that I'm not including any of them here,
  111.       because they really are beyond the scope of this list.
  112.  
  113.       You might like to check out the documentation for the "curses"
  114.       library of portable screen functions.  Often if you're interested
  115.       in single-character I/O like this, you're also interested in
  116.       doing some sort of screen display control, and the curses library
  117.       provides various portable routines for both functions.
  118.  
  119. ------------------------------
  120.  
  121. Subject: How do I check to see if there are characters to be read ... ?
  122. Date: Thu Mar 18 17:16:55 EST 1993
  123.  
  124. 4.2)  How do I check to see if there are characters to be read without
  125.       actually reading?
  126.  
  127.       Certain versions of UNIX provide ways to check whether characters
  128.       are currently available to be read from a file descriptor.  In
  129.       BSD, you can use select(2).  You can also use the FIONREAD ioctl
  130.       (see tty(4)), which returns the number of characters waiting to
  131.       be read, but only works on terminals, pipes and sockets.  In
  132.       System V Release 3, you can use poll(2), but that only works on
  133.       streams.  In Xenix - and therefore Unix SysV r3.2 and later - the
  134.       rdchk() system call reports whether a read() call on a given file
  135.       descriptor will block.
  136.  
  137.       There is no way to check whether characters are available to be
  138.       read from a FILE pointer.  (You could poke around inside stdio
  139.       data structures to see if the input buffer is nonempty, but that
  140.       wouldn't work since you'd have no way of knowing what will happen
  141.       the next time you try to fill the buffer.)
  142.  
  143.       Sometimes people ask this question with the intention of writing
  144.         if (characters available from fd)
  145.             read(fd, buf, sizeof buf);
  146.       in order to get the effect of a nonblocking read.  This is not
  147.       the best way to do this, because it is possible that characters
  148.       will be available when you test for availability, but will no
  149.       longer be available when you call read.  Instead, set the
  150.       O_NDELAY flag (which is also called FNDELAY under BSD) using the
  151.       F_SETFL option of fcntl(2).  Older systems (Version 7, 4.1 BSD)
  152.       don't have O_NDELAY; on these systems the closest you can get to
  153.       a nonblocking read is to use alarm(2) to time out the read.
  154.  
  155. ------------------------------
  156.  
  157. Subject: How do I find the name of an open file?
  158. Date: Thu Mar 18 17:16:55 EST 1993
  159.  
  160. 4.3)  How do I find the name of an open file?
  161.  
  162.       In general, this is too difficult.  The file descriptor may
  163.       be attached to a pipe or pty, in which case it has no name.
  164.       It may be attached to a file that has been removed.  It may
  165.       have multiple names, due to either hard or symbolic links.
  166.  
  167.       If you really need to do this, and be sure you think long
  168.       and hard about it and have decided that you have no choice,
  169.       you can use find with the -inum and possibly -xdev option,
  170.       or you can use ncheck, or you can recreate the functionality
  171.       of one of these within your program.  Just realize that
  172.       searching a 600 megabyte filesystem for a file that may not
  173.       even exist is going to take some time.
  174.  
  175. ------------------------------
  176.  
  177. Subject: How can an executing program determine its own pathname?
  178. Date: Thu Mar 18 17:16:55 EST 1993
  179.  
  180. 4.4)  How can an executing program determine its own pathname?
  181.  
  182.       Your program can look at argv[0]; if it begins with a "/", it is
  183.       probably the absolute pathname to your program, otherwise your
  184.       program can look at every directory named in the environment
  185.       variable PATH and try to find the first one that contains an
  186.       executable file whose name matches your program's argv[0] (which
  187.       by convention is the name of the file being executed).  By
  188.       concatenating that directory and the value of argv[0] you'd
  189.       probably have the right name.
  190.  
  191.       You can't really be sure though, since it is quite legal for one
  192.       program to exec() another with any value of argv[0] it desires.
  193.       It is merely a convention that new programs are exec'd with the
  194.       executable file name in argv[0].
  195.  
  196.       For instance, purely a hypothetical example:
  197.     
  198.     #include <stdio.h>
  199.     main()
  200.     {
  201.         execl("/usr/games/rogue", "vi Thesis", (char *)NULL);
  202.     }
  203.  
  204.       The executed program thinks its name (its argv[0] value) is
  205.       "vi Thesis".   (Certain other programs might also think that
  206.       the name of the program you're currently running is "vi Thesis",
  207.       but of course this is just a hypothetical example, don't
  208.       try it yourself :-)
  209.  
  210. ------------------------------
  211.  
  212. Subject: How do I use popen() to open a process for reading AND writing?
  213. Date: Thu Mar 18 17:16:55 EST 1993
  214.  
  215. 4.5)  How do I use popen() to open a process for reading AND writing?
  216.  
  217.       The problem with trying to pipe both input and output to an
  218.       arbitrary slave process is that deadlock can occur, if both
  219.       processes are waiting for not-yet-generated input at the same
  220.       time.  Deadlock can be avoided only by having BOTH sides follow a
  221.       strict deadlock-free protocol, but since that requires
  222.       cooperation from the processes it is inappropriate for a
  223.       popen()-like library function.
  224.  
  225.       The 'expect' distribution includes a library of functions that a
  226.       C programmer can call directly.  One of the functions does the
  227.       equivalent of a popen for both reading and writing.  It uses ptys
  228.       rather than pipes, and has no deadlock problem.  It's portable to
  229.       both BSD and SV.  See the next answer for more about 'expect'.
  230.  
  231. ------------------------------
  232.  
  233. Subject: How do I sleep() in a C program for less than one second?
  234. Date: Thu Mar 18 17:16:55 EST 1993
  235.  
  236. 4.6)  How do I sleep() in a C program for less than one second?
  237.  
  238.       The first thing you need to be aware of is that all you can
  239.       specify is a MINIMUM amount of delay; the actual delay will
  240.       depend on scheduling issues such as system load, and could be
  241.       arbitrarily large if you're unlucky.
  242.  
  243.       There is no standard library function that you can count on in
  244.       all environments for "napping" (the usual name for short
  245.       sleeps).  Some environments supply a "usleep(n)" function which
  246.       suspends execution for n microseconds.  If your environment
  247.       doesn't support usleep(), here are a couple of implementations
  248.       for BSD and System V environments.
  249.  
  250.       The following code is adapted from Doug Gwyn's System V emulation
  251.       support for 4BSD and exploits the 4BSD select() system call.
  252.       Doug originally called it 'nap()'; you probably want to call it
  253.       "usleep()";
  254.  
  255.       /*
  256.         usleep -- support routine for 4.2BSD system call emulations
  257.         last edit:    29-Oct-1984    D A Gwyn
  258.       */
  259.  
  260.       extern int    select();
  261.  
  262.       int
  263.       usleep( usec )                /* returns 0 if ok, else -1 */
  264.         long        usec;        /* delay in microseconds */
  265.         {
  266.         static struct            /* `timeval' */
  267.             {
  268.             long    tv_sec;        /* seconds */
  269.             long    tv_usec;    /* microsecs */
  270.             }    delay;        /* _select() timeout */
  271.  
  272.         delay.tv_sec = usec / 1000000L;
  273.         delay.tv_usec = usec % 1000000L;
  274.  
  275.         return select( 0, (long *)0, (long *)0, (long *)0, &delay );
  276.         }
  277.  
  278.       On System V you might do it this way:
  279.  
  280.       /*
  281.       subseconds sleeps for System V - or anything that has poll()
  282.       Don Libes, 4/1/1991
  283.  
  284.       The BSD analog to this function is defined in terms of
  285.       microseconds while poll() is defined in terms of milliseconds.
  286.       For compatibility, this function provides accuracy "over the long
  287.       run" by truncating actual requests to milliseconds and
  288.       accumulating microseconds across calls with the idea that you are
  289.       probably calling it in a tight loop, and that over the long run,
  290.       the error will even out.
  291.  
  292.       If you aren't calling it in a tight loop, then you almost
  293.       certainly aren't making microsecond-resolution requests anyway,
  294.       in which case you don't care about microseconds.  And if you did,
  295.       you wouldn't be using UNIX anyway because random system
  296.       indigestion (i.e., scheduling) can make mincemeat out of any
  297.       timing code.
  298.  
  299.       Returns 0 if successful timeout, -1 if unsuccessful.
  300.  
  301.       */
  302.  
  303.       #include <poll.h>
  304.  
  305.       int
  306.       usleep(usec)
  307.       unsigned int usec;        /* microseconds */
  308.       {
  309.         static subtotal = 0;    /* microseconds */
  310.         int msec;            /* milliseconds */
  311.  
  312.         /* 'foo' is only here because some versions of 5.3 have
  313.          * a bug where the first argument to poll() is checked
  314.          * for a valid memory address even if the second argument is 0.
  315.          */
  316.         struct pollfd foo;
  317.  
  318.         subtotal += usec;
  319.         /* if less then 1 msec request, do nothing but remember it */
  320.         if (subtotal < 1000) return(0);
  321.         msec = subtotal/1000;
  322.         subtotal = subtotal%1000;
  323.         return poll(&foo,(unsigned long)0,msec);
  324.       }
  325.  
  326.       Another possibility for nap()ing on System V, and probably other
  327.       non-BSD Unices is Jon Zeeff's s5nap package, posted to
  328.       comp.sources.misc, volume 4.  It does require a installing a
  329.       device driver, but works flawlessly once installed.  (Its
  330.       resolution is limited to the kernel HZ value, since it uses the
  331.       kernel delay() routine.)
  332.  
  333. ------------------------------
  334.  
  335. Subject: How can I get setuid shell scripts to work?
  336. Date: Thu Mar 18 17:16:55 EST 1993
  337.  
  338. 4.7)  How can I get setuid shell scripts to work?
  339.  
  340.       [ This is a long answer, but it's a complicated and frequently-asked
  341.         question.  Thanks to Maarten Litmaath for this answer, and
  342.         for the "indir" program mentioned below. ]
  343.  
  344.       Let us first assume you are on a UNIX variant (e.g. 4.3BSD or
  345.       SunOS) that knows about so-called `executable shell scripts'.
  346.       Such a script must start with a line like:
  347.  
  348.     #!/bin/sh
  349.  
  350.       The script is called `executable' because just like a real (binary)
  351.       executable it starts with a so-called `magic number' indicating
  352.       the type of the executable.  In our case this number is `#!' and
  353.       the OS takes the rest of the first line as the interpreter for
  354.       the script, possibly followed by 1 initial option like:
  355.  
  356.     #!/bin/sed -f
  357.  
  358.       Suppose this script is called `foo' and is found in /bin,
  359.       then if you type:
  360.  
  361.     foo arg1 arg2 arg3
  362.  
  363.       the OS will rearrange things as though you had typed:
  364.  
  365.     /bin/sed -f /bin/foo arg1 arg2 arg3
  366.  
  367.       There is one difference though: if the setuid permission bit for
  368.       `foo' is set, it will be honored in the first form of the
  369.       command; if you really type the second form, the OS will honor
  370.       the permission bits of /bin/sed, which is not setuid, of course.
  371.  
  372.       ----------
  373.  
  374.       OK, but what if my shell script does NOT start with such a `#!'
  375.       line or my OS does not know about it?
  376.  
  377.       Well, if the shell (or anybody else) tries to execute it, the OS
  378.       will return an error indication, as the file does not start with
  379.       a valid magic number.  Upon receiving this indication the shell
  380.       ASSUMES the file to be a shell script and gives it another try:
  381.  
  382.     /bin/sh shell_script arguments
  383.  
  384.       But we have already seen that a setuid bit on `shell_script' will
  385.       NOT be honored in this case!
  386.  
  387.       ----------
  388.  
  389.       Right, but what about the security risks of setuid shell scripts?
  390.  
  391.       Well, suppose the script is called `/etc/setuid_script', starting
  392.       with:
  393.  
  394.     #!/bin/sh
  395.     
  396.       Now let us see what happens if we issue the following commands:
  397.  
  398.     $ cd /tmp
  399.     $ ln /etc/setuid_script -i
  400.     $ PATH=.
  401.     $ -i
  402.  
  403.       We know the last command will be rearranged to:
  404.  
  405.     /bin/sh -i
  406.  
  407.       But this command will give us an interactive shell, setuid to the
  408.       owner of the script!
  409.       Fortunately this security hole can easily be closed by making the
  410.       first line:
  411.  
  412.     #!/bin/sh -
  413.  
  414.       The `-' signals the end of the option list: the next argument `-i'
  415.       will be taken as the name of the file to read commands from, just
  416.       like it should!
  417.  
  418.       ---------
  419.  
  420.       There are more serious problems though:
  421.  
  422.     $ cd /tmp
  423.     $ ln /etc/setuid_script temp
  424.     $ nice -20 temp &
  425.     $ mv my_script temp
  426.  
  427.       The third command will be rearranged to:
  428.  
  429.     nice -20 /bin/sh - temp
  430.  
  431.       As this command runs so slowly, the fourth command might be able
  432.       to replace the original `temp' with `my_script' BEFORE `temp' is
  433.       opened by the shell!  There are 4 ways to fix this security hole:
  434.  
  435.     1)  let the OS start setuid scripts in a different, secure way
  436.         - System V R4 and 4.4BSD use the /dev/fd driver to pass the
  437.         interpreter a file descriptor for the script
  438.  
  439.     2)  let the script be interpreted indirectly, through a frontend
  440.         that makes sure everything is all right before starting the
  441.         real interpreter - if you use the `indir' program from
  442.         comp.sources.unix the setuid script will look like this:
  443.  
  444.         #!/bin/indir -u
  445.         #?/bin/sh /etc/setuid_script
  446.  
  447.     3)  make a `binary wrapper': a real executable that is setuid and
  448.         whose only task is to execute the interpreter with the name of
  449.         the script as an argument
  450.  
  451.     4)  make a general `setuid script server' that tries to locate the
  452.         requested `service' in a database of valid scripts and upon
  453.         success will start the right interpreter with the right
  454.         arguments.
  455.  
  456.       ---------
  457.  
  458.       Now that we have made sure the right file gets interpreted, are
  459.       there any risks left?
  460.  
  461.       Certainly!  For shell scripts you must not forget to set the PATH
  462.       variable to a safe path explicitly.  Can you figure out why?
  463.       Also there is the IFS variable that might cause trouble if not
  464.       set properly.  Other environment variables might turn out to
  465.       compromise security as well, e.g. SHELL...  Furthermore you must
  466.       make sure the commands in the script do not allow interactive
  467.       shell escapes!  Then there is the umask which may have been set
  468.       to something strange...
  469.  
  470.       Etcetera.  You should realise that a setuid script `inherits' all
  471.       the bugs and security risks of the commands that it calls!
  472.  
  473.       All in all we get the impression setuid shell scripts are quite a
  474.       risky business!  You may be better off writing a C program instead!
  475.  
  476. ------------------------------
  477.  
  478. Subject: How can I find out which user or process has a file open ... ?
  479. Date: Thu Mar 18 17:16:55 EST 1993
  480.  
  481. 4.8)  How can I find out which user or process has a file open or is using
  482.       a particular file system (so that I can unmount it?)
  483.  
  484.       Use fuser (system V), fstat (BSD), ofiles (public domain) or
  485.       pff (public domain).  These programs will tell you various things
  486.       about processes using particular files.
  487.  
  488.       A port of the 4.3 BSD fstat to Dynix, SunOS and Ultrix
  489.       can be found in archives of comp.sources.unix, volume 18.
  490.  
  491.       pff is part of the kstuff package, and works on quite a few systems.
  492.       Instructions for obtaining kstuff are provided in question 3.10.
  493.  
  494. ------------------------------
  495.  
  496. Subject: How do I keep track of people who are fingering me?
  497. >From: jik@rtfm.MIT.EDU (Jonathan I. Kamens)
  498. >From: malenovi@plains.NoDak.edu (Nikola Malenovic)
  499. Date: Mon, 23 Nov 1992 16:01:45 -0600
  500.  
  501. 4.9)  How do I keep track of people who are fingering me?
  502.  
  503.       Generally, you can't find out the userid of someone who is
  504.       fingering you from a remote machine.  You may be able to
  505.       find out which machine the remote request is coming from.
  506.       One possibility, if your system supports it and assuming
  507.       the finger daemon doesn't object, is to make your .plan file a
  508.       "named pipe" instead of a plain file.  (Use 'mknod' to do this.)
  509.  
  510.       You can then start up a program that will open your .plan file
  511.       for writing; the open will block until some other process (namely
  512.       fingerd) opens the .plan for reading.  Now you can whatever you
  513.       want through this pipe, which lets you show different .plan
  514.       information every time someone fingers you.
  515.  
  516.       Of course, this may not work at all if your system doesn't
  517.       support named pipes or if your local fingerd insists
  518.       on having plain .plan files.
  519.  
  520.       Your program can also take the opportunity to look at the output
  521.       of "netstat" and spot where an incoming finger connection is
  522.       coming from, but this won't get you the remote user.
  523.  
  524.       Getting the remote userid would require that the remote site be
  525.       running an identity service such as RFC 931.  There are now three
  526.       RFC 931 implementations for popular BSD machines, and several
  527.       applications (such as the wuarchive ftpd) supporting the server.
  528.       For more information join the rfc931-users mailing list,
  529.       rfc931-users-request@kramden.acf.nyu.edu.
  530.  
  531.       There are three caveats relating to this answer.  The first is
  532.       that many NFS systems won't recognize the named pipe correctly.
  533.       This means that trying to read the pipe on another machine will
  534.       either block until it times out, or see it as a zero-length file,
  535.       and never print it.
  536.  
  537.       The second problem is that on many systems, fingerd checks that
  538.       the .plan file contains data (and is readable) before trying to
  539.       read it.  This will cause remote fingers to miss your .plan file
  540.       entirely.
  541.  
  542.       The third problem is that a system that supports named pipes
  543.       usually has a fixed number of named pipes available on the
  544.       system at any given time - check the kernel config file and
  545.       FIFOCNT option.  If the number of pipes on the system exceeds the
  546.       FIFOCNT value, the system blocks new pipes until somebody frees
  547.       the resources.  The reason for this is that buffers are allocated
  548.       in a non-paged memory.
  549.  
  550. ------------------------------
  551.  
  552. Subject: Is it possible to reconnect a process to a terminal ... ?
  553. Date: Thu Mar 18 17:16:55 EST 1993
  554.  
  555. 4.10) Is it possible to reconnect a process to a terminal after it has
  556.       been disconnected, e.g. after starting a program in the background
  557.       and logging out?
  558.  
  559.       Most variants of Unix do not support "detaching" and "attaching"
  560.       processes, as operating systems such as VMS and Multics support.
  561.       However, there are two freely redistributable packages which can
  562.       be used to start processes in such a way that they can be later
  563.       reattached to a terminal.
  564.  
  565.       The first is "screen," which is described in the
  566.       comp.sources.unix archives as "Screen, multiple windows on a CRT"
  567.       (see the "screen-3.2" package in comp.sources.misc, volume 28.)
  568.       This package will run on at least BSD, System V r3.2 and SCO UNIX.
  569.  
  570.       The second is "pty," which is described in the comp.sources.unix
  571.       archives as a package to "Run a program under a pty session" (see
  572.       "pty" in volume 23).  pty is designed for use under BSD-like
  573.       system only.
  574.  
  575.       Neither of these packages is retroactive, i.e. you must have
  576.       started a process under screen or pty in order to be able to
  577.       detach and reattach it.
  578.  
  579. ------------------------------
  580.  
  581. Subject: Is it possible to "spy" on a terminal ... ?
  582. Date: Thu Mar 18 17:16:55 EST 1993
  583.  
  584. 4.11) Is it possible to "spy" on a terminal, displaying the output
  585.       that's appearing on it on another terminal?
  586.  
  587.       There are a few different ways you can do this, although none
  588.       of them is perfect:
  589.  
  590.       * kibitz allows two (or more) people to interact with a shell
  591.         (or any arbitary program).  Uses include:
  592.  
  593.     - watching or aiding another person's terminal session;
  594.     - recording a conversation while retaining the ability to
  595.       scroll backwards, save the conversation, or even edit it
  596.       while in progress;
  597.     - teaming up on games, document editing, or other cooperative
  598.       tasks where each person has strengths and weakness that
  599.       complement one another.
  600.  
  601.         kibitz comes as part of the expect distribution.  See question 3.9.
  602.  
  603.         kibitz requires permission from the person to be spyed upon.  To
  604.         spy without permission requires less pleasant approaches:
  605.  
  606.       * You can write a program that grovels through Kernel structures
  607.         and watches the output buffer for the terminal in question,
  608.         displaying characters as they are output.  This, obviously, is
  609.         not something that should be attempted by anyone who does not
  610.         have experience working with the Unix kernel.  Furthermore,
  611.         whatever method you come up with will probably be quite
  612.         non-portable.
  613.  
  614.       * If you want to do this to a particular hard-wired terminal all
  615.         the time (e.g. if you want operators to be able to check the
  616.         console terminal of a machine from other machines), you can
  617.         actually splice a monitor into the cable for the terminal.  For
  618.         example, plug the monitor output into another machine's serial
  619.         port, and run a program on that port that stores its input
  620.         somewhere and then transmits it out *another* port, this one
  621.         really going to the physical terminal.  If you do this, you have
  622.         to make sure that any output from the terminal is transmitted
  623.         back over the wire, although if you splice only into the
  624.         computer->terminal wires, this isn't much of a problem.  This is
  625.         not something that should be attempted by anyone who is not very
  626.         familiar with terminal wiring and such.
  627.  
  628. ------------------------------
  629.  
  630. End of unix/faq Digest part 4 of 7
  631. **********************************
  632.  
  633. -- 
  634. Ted Timar - tmatimar@empress.com
  635. Empress Software, 3100 Steeles Ave E, Markham, Ont., Canada L3R 8T3
  636.