home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / Documents / FAQ / Unix-faq / part4 < prev    next >
Encoding:
Text File  |  1993-08-23  |  25.8 KB  |  639 lines

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