Diffs to the Frequently Asked Questions postings
Steve Hayman
sahayman at iuvax.cs.indiana.edu
Fri May 3 09:44:25 AEST 1991
Here are the most recent changes to parts 1 and 2 of the
Frequently Asked Questions articles, which have just been
posted. You can find the full articles elsewhere in
comp.unix.questions. You can also ftp the most recent version from
iuvax.cs.indiana.edu (129.79.254.192), where it's
"pub/Unix-Questions.part1" and "pub/Unix-Questions.part2".
(IUVax also runs a mail server, for those of you unable to ftp.
Send the line "HELP" to "mailserv at iuvax.cs.indiana.edu" to get started.)
***************
*** 1,6 ****
Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting]
! [Last changed: $Date: 91/04/02 17:13:41 $ by $Author: sahayman $]
This article contains the answers to some Frequently Asked Questions
often seen in comp.unix.questions. Please don't ask these questions
--- 1,6 ----
Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting]
! [Last changed: $Date: 91/05/02 18:39:31 $ by $Author: sahayman $]
This article contains the answers to some Frequently Asked Questions
often seen in comp.unix.questions. Please don't ask these questions
***************
*** 58,64 ****
32) How do I find the last argument in a Bourne shell script?
33) How can I find out which user or process has a file open or is using
a particular file system (so that I can unmount it?)
! 34) What happened to the pronunciation list that used to be
part of this document?
--- 58,67 ----
32) How do I find the last argument in a Bourne shell script?
33) How can I find out which user or process has a file open or is using
a particular file system (so that I can unmount it?)
! 34) How do I keep track of people who are fingering me?
! 35) How do I find out the process ID of a program with a particular
! name from inside a shell script or C program?
! 36) What happened to the pronunciation list that used to be
part of this document?
***************
*** 1345,1354 ****
The following code is adapted from Doug Gwyn's System V emulation
support for 4BSD and exploits the 4BSD select() system call.
! (You probably want to call it "usleep()" instead of "nap()" )
/*
! nap -- support routine for 4.2BSD system call emulations
last edit: 29-Oct-1984 D A Gwyn
*/
--- 1348,1358 ----
The following code is adapted from Doug Gwyn's System V emulation
support for 4BSD and exploits the 4BSD select() system call.
! Doug originally called it 'nap()'; you probably want to call it
! "usleep()";
/*
! usleep -- support routine for 4.2BSD system call emulations
last edit: 29-Oct-1984 D A Gwyn
*/
***************
*** 1357,1363 ****
int
! nap( usec ) /* returns 0 if ok, else -1 */
long usec; /* delay in microseconds */
{
static struct /* `timeval' */
--- 1361,1367 ----
int
! usleep( usec ) /* returns 0 if ok, else -1 */
long usec; /* delay in microseconds */
{
static struct /* `timeval' */
***************
*** 1403,1416 ****
unsigned int usec; /* microseconds */
{
static subtotal = 0; /* microseconds */
! int msec; /* milliseconds */
subtotal += usec;
/* if less then 1 msec request, do nothing but remember it */
if (subtotal < 1000) return(0);
msec = subtotal/1000;
subtotal = subtotal%1000;
! return poll((struct pollfd *)0,(unsigned long)0,msec);
}
--- 1407,1426 ----
unsigned int usec; /* microseconds */
{
static subtotal = 0; /* microseconds */
! int msec; /* milliseconds */
+ /* 'foo' is only here because some versions of 5.3 have
+ * a bug where the first argument to poll() is checked
+ * for a valid memory address even if the second argument is 0.
+ */
+ struct pollfd foo;
+
subtotal += usec;
/* if less then 1 msec request, do nothing but remember it */
if (subtotal < 1000) return(0);
msec = subtotal/1000;
subtotal = subtotal%1000;
! return poll(&foo,(unsigned long)0,msec);
}
***************
*** 1588,1594 ****
.[!.]* (Newer shells only; some shells use a "^" instead of
the "!"; POSIX shells must accept the "!", but may
! accept a "^" as well; all portable application shall
not use an unquoted "^" immediately following the "[")
Matches all files that begin with a "." and are
--- 1598,1604 ----
.[!.]* (Newer shells only; some shells use a "^" instead of
the "!"; POSIX shells must accept the "!", but may
! accept a "^" as well; all portable applications shall
not use an unquoted "^" immediately following the "[")
Matches all files that begin with a "." and are
***************
*** 1599,1611 ****
at least 3 characters long. This neatly avoids
"." and "..", but also misses ".a" .
!
! Many people are willing to use .??* to match all dotfiles
! (or * .??* to match all files) even though that pattern doesn't
! get everything - it has the advantage of being easy to type.
! If you really do want to be sure, you'll need to employ
! an external program or two and use backquote substitution.
! This is pretty good:
`ls -a | sed -e '/^\.$/d' -e '/^\.\.$/d'`
--- 1609,1622 ----
at least 3 characters long. This neatly avoids
"." and "..", but also misses ".a" .
! So to match all files except "." and ".." safely you have to use
! 3 patterns (if you don't have filenames like ".a" you can leave out
! the first):
!
! .[!.] .??* *
!
! Alternatively you could employ an external program or two and use
! backquote substitution. This is pretty good:
`ls -a | sed -e '/^\.$/d' -e '/^\.\.$/d'`
***************
*** 1726,1732 ****
can be found in archives of comp.sources.unix, volume 18.
! 34) What happened to the pronunciation list that used to be
part of this document?
Since its inception in 1989, this FAQ document included a comprehensive
--- 1737,1824 ----
can be found in archives of comp.sources.unix, volume 18.
! 34) How do I keep track of people who are fingering me?
!
! Generally, you can't find out the userid of someone who is
! fingering you from a remote machine. You may be able to
! find out which machine the remote request is coming from.
! One possibility, if your system supports it and assuming
! the finger daemon doesn't object, is to make your .plan file a
! "named pipe" instead of a plain file. (Use 'mknod' to do this.)
!
! You can then start up a program that will open your .plan file
! for writing; the open will block until some other process
! (namely fingerd) opens the .plan for reading. Now, not only
! can you write whatever you want through this pipe (which lets
! you show different .plan information every time someone
! fingers you), you can use getpeername() to find out the name of the
! peer connected to this socket, which will let you find out from
! which remote machine the finger request originates.
!
! Of course, this may not work at all if your system doesn't
! support named pipes or if your local fingerd insists
! on having plain .plan files.
!
! Getting the remote userid would require that the remote site be
! running some sort of RFC931-style authorization daemon, which
! relatively few sites currently run.
!
! 35) How do I find out the process ID of a program with a particular
! name from inside a shell script or C program?
!
! In a shell script:
!
! There is no utility specifically designed to map between program names
! and process IDs. Furthermore, such mappings are often unreliable,
! since it's possible for more than one process to have the same name,
! and since it's possible for a process to change its name once it
! starts running. However, a pipeline like this can often be used to
! get a list of processes (owned by you) with a particular name:
!
! ps ux | awk '/name/ && !/awk/ {print $2}'
!
! You replace "name" with the name of the process for which you are
! searching.
!
! The general idea is to parse the output of ps, using awk or grep or
! other utilities, to search for the lines with the specified name on
! them, and print the PID's for those lines. Note that the "!/awk/"
! above prevents the awk process for being listed.
!
! You may have to change the arguments to ps, depending on what kind of
! Unix you are using.
!
! In a C program:
!
! Just as there is no utility specifically designed to map between
! program names and process IDs, there are no (portable) C library
! functions to do it either.
!
! However, some vendors provide functions for reading Kernel memory; for
! example, Sun provides the "kvm_" functions, and Data General provides
! the "dg_" functions. It may be possible for any user to use these, or
! they may only be useable by the super-user (or a user in group "kmem")
! if read-access to kernel memory on your system is restricted.
! Furthermore, these functions are often not documented or documented
! badly, and might change from release to release.
!
! Some vendors provide a "/proc" filesystem, which appears as a
! directory with a bunch of filenames in it. Each filename is a number,
! corresponding to a process ID, and you can open the file and read it
! to get information about the process. Once again, access to this may
! be restricted, and the interface to it may change from system to
! system.
!
! If you can't use vendor-specific library functions, and you don't have
! /proc, and you still want to do this completely in C, you are going to
! have to do the grovelling through kernel memory yourself. For a good
! example of how to do this on many systems, see the sources to
! "ofiles", available in the comp.sources.unix archives.
!
! If all else fails, you can call popen() on "ps" and parse its output.
!
!
! 36) What happened to the pronunciation list that used to be
part of this document?
Since its inception in 1989, this FAQ document included a comprehensive
More information about the Comp.unix.questions
mailing list