home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / unix-faq / faq / part4 < prev    next >
Encoding:
Text File  |  2004-05-12  |  28.8 KB  |  685 lines

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