- ...routines
- By definition, a reentrant routine is a piece of code that
can be entered before its completion and still execute correctly. This
implies that a reentrant routine must not be allowed to modify its
instructions. Yet self-modification is sometimes a very useful technique,
especially for low-level routines, so why it doesn't work with reentrant
code?
Also, you may have already encountered reentrant routines when dealing with
recursive procedures written in a programming language like Pascal or C. Why
is some form of reentrance mandatory for implementing these constructs? In
what these implementations differ from reentrance between programs in a
multiprogramming environment?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...record
- This pointer is often implicit, in the sense that a
stack of records is mantained, with the the record of the newest activation
on top. Try to describe to yourself how this mechanism works...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...code
- ...or the fragment that's being executed at a given time, as is
often the case for systems that make use of virtual memory
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...OS
- or rather in the scheduler of an OS, which is the
subsystem dealing with the policy of process dispatching
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...involved
- ...and because of the undefeated programmers'
tendency to use all the available resources for their applications, which
implies that more memory usually means larger processes, and not more
processes instead...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...value
- Depending on
the algorithms used to implement a priority scheme for sharing CPU usage
among processes, more than one ``priority'' value for the process may be
recorded, and some of them may change with time
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...delay
- ...according to the scheduling policy in use: the
CPU resources are invariably limited, hence there's no way to satisfy all
possible scheduling wishes
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...them
- In the jargon this condition is
expressively called trashing.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...routine
- Note that this is worse
than having a slow, but guaranteed, response time. It means that the
controller is time-variant: sometimes it has a huge inertia, sometimes it
hasn't; sometimes it's so slow that the plant goes astray before the
controller gets to know about, sometimes it's so fast that the plant is
forced to jump around like crazy and never reaches a nice steady regime.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...networks
- See the Dec. 94 issue of em Byte for an interesting
discussion of threaded server implementations under MS WindowsNT, using the
Winsock protocols.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...termination)
- This is different than having a parent
terminated before the child. In this case the child is simply adopted by
process 1, init.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...UNIX
- except process 0, swapper, and process
-1, pager
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...API
- API =
Application Programmer's Interface, i.e. the interface (usually a layer of
library functions) through which an application programmer can specify the
use of the services provided by of some software system in his/her
high-level language source code
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...available
- A simpler, more rigid but
portable, way to generate error message is provided by the perror()
library function (which is standard in ANSI C, while sys_errlist and
errno are UNIX specific). You may want to check its manual page.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...flavors,
- Well, actually four, but nobody cares about System
V's wait4().
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...exit()
- ..or to the return
statement of the main() function, if the child is a complete C
program
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...assumed
- ...at the very least, you can
simply think that all the files we are talking about are just sequences of
bytes stored on a disk, and that they are in the same disk directory as the
program that uses them: only a file's name, and not its physical disk
location, is then relevant to the discussion
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...so
- BSD and System V guarantee only that each process has at
least 20 slots in the object reference table, but this limit can be
configured on system installation. the getdtablesize() system call can
be used to ask the system what the actual table size is.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...functions
- More precisely,
since in UNIX the stream-oriented functions are implemented in terms of the
block-oriented ones, a file descriptor is one of the fields of a FILE
structure. So, if you have opened a FILE *fp in the stream-oriented
mode with fopen(), and then want to perform some low-level operations
on it, you will first need to find its associated file descriptor using the
fileno(fp) macro. Conversely, the fdopen(fd, "r") stream
library is used to ``convert'' a file descriptor fd into a FILE
pointer open for reading ("w" for writing, etc.). Once more, be warned that
these calls are UNIX specific, though some other systems use a similar file
descriptor mechanism for low level I/O.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...them
- The precise header names
can change with the UNIX flavor you are using. As usual, the ultimate
reference is the manual page.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...mask
- actually
there's more than that, but we won't deal with the so called special
files until much later in the course.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...optional
- An often
overlooked characteristic of C is that a function can be arranged so to have
a number of parameters not specified at compile time. Yet every C
programmer routinely uses functions like printf(), which can take in
pronciple any number of parameters. Check the section on the
``variable argument lists'' or ``va_lists'' in your C book to learn more
about.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...read
- ...which
might be less than those requested, if there weren't that many left in the
file, starting from the current seek position onward...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...located
- ...actually not: there are security reasons for never ever
putting the current directory, ".", in the PATH. But this is just the
simplest security hole that an undergrad wishing to peek in instructors'
assignment files must know about. An easily blocked one, unfortunately...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...element
- So, for example, if envp contains ten environment
variables, then envp[10]==NULL.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...optional
- ...so optional that it's not even in the ANSI standard for
C, and this is why your compiler may yell at you if you try to use a
main() like the above. The ANSI and Posix committees declared that every
C program must access the environment through a global external pointer,
declared as extern char *environ[], whose content is exactly as
envp above. Amen.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...O_WRONLY?)
- Posix defines in unistd.h three
constants for these file descriptors, STDIN_FILENO for standard input,
STDOUT_FILENO for standard output, STDERR_FILENO for standard error. The
use of theses named constants is to be preferred to the numbers for
portability, since system implementors free to change the numbers as they
wish.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...linker
- The system
can figure out if it's an executable by looking for a ``magic number'' in
the first few bytes of the file: man a.out, for those eager to know more
about magic cookies.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...script
- If you are not familiar with UNIX shell scripts yet, think of
them as akin to ``.BAT'' files in M$-DOG, only much better, and then go
fetch yourself Kernighan & Pike's gospel down at the library.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...constraint
- There's actually one, but it's much looser. For
efficiency reasons, the system has to use tables of fixed size to hold the
arguments, so there's a limit to the size that the whole argv string
array can attain, and it's specified via the ARG_MAX constant, in the
sys/limit.h header. This is several kilobytes at least, so if you
happen to have to worry about, it probably means that you are trying to
shoot yourself in a foot with a battleship cannon: you know, ``arguments''
can be read from a file too ...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...it
- Warning: a naive
implementation, i.e. one that just substitutes read() with fgets(), write()
with fputs(), and pipe() with popen(), will possibly hang doing nothing. If
this happens, the problem is in the stream buffering: check out the manpage
for setvbuf().
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...file
- ...hence as an octal value encoding the appropriate access
bits in owner-group-world order. Constants are provided for this purpose
too:
SEM_R for owner read and SEM_W for owner write;
SEM_R>>3 for group read and SEM_W>>3 for group write;
SEM_R>>6 for world read and SEM_W>>6 for world write;
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...sleep
- ...hence the sequence of steps
for accessing a shared resource controlled by a semaphore becomes: (1) test
the semaphore that controls the resource; (2) if the counter is positive,
decrement it by one and access the resource; (3) if, otherwise, it's zero,
sleep until it gets positive, and return to step 1 on wakeup; (4) increment
by one the counter when done using the resource.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...usage
- ...and if you find that those details make
sense and have the elegance their authors claim, please let me know: one
personal idea of common sense and elegance would need revising, either mine
or yours.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...possible
- ...where ``possible'' refers more to execution
capability than to size: we'll meet later a phenomenon called ``trashing''
that imposes a limit on the number of active processes way below the
physical capabilities of main memory
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...UNIX
- What follows is largely based on the
article ``4.2BSD and 4.3BSD as Examples of the UNIX System'', by J. S.
Quaterman, A. Silbershatz and J. L. Peterson, appeared on Computing
Surveys, 17(4), Dec. 1985.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...run
- As we'll
see later, System V R4 uses the opposite convention, otherwise users' life
would be too easy...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...data.
- Here the term relation is used strictly in its
set-theoretical meaning: a relation R among the sets
is, by definition, a subset of their cartesian product
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...FMS
- ...not to be confused with
the file system, which is a data structure used to organize files on
disk.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...search
- A dicotomic (or
binary, or divide et impera) search for the record with a given key proceeds
as follows: (1) Define the `` section'' of the file as the entire file; (2)
compare the search key with the one of the record at the middle of the
section; (3) if they are equal return the record; (4) otherwise, if the
search key is higher, define the section to be the next half of the current
one; (4.1) otherwise, define the section to be the previous half; (5) if the
section has zero size, return with ``not found'' error; (6) goto 2.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...system
- In other words, the FMS
offers to users/applications directory modification services in the
form of commands or system calls, so that it can protect the fyle system
integrity by allowing only ``correct'' operations.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...layers
- From lowest to highest, phisical, datalink, network,
transport, session, presentation, application.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ...Unix).
- By extension, the term server is also
used to indicate a computer which, through some server application, provides
some service for other computers connected to it via a network. The most
common example is a file server which has a local disk and services requests
from remote clients to read and write files on that disk, often using Sun's
Network Filing System (NFS) protocol or Novell Netware on IBM PCs.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.