[Info-vax] VMS Forever?
MetaEd
metaed at gmail.com
Fri Apr 24 15:17:10 EDT 2009
On Apr 24, 11:55 am, yyyc186 <yyyc... at hughes.net> wrote:
> On Apr 20, 9:44 pm, Arne Vajhøj <a... at vajhoej.dk> wrote:
>
>
>
> > yyyc186 wrote:
> > > On Apr 15, 8:52 pm, Arne Vajhøj <a... at vajhoej.dk> wrote:
> > >> The VMS way:
> > >> - CLI is in P1
> > >> - programs run in P0
> > >> - one process = one CLI
>
> > >> The Unix way:
> > >> - shell is just a program
> > >> - programs run in P0
> > >> - every program is a new process
>
> > > You mean thread, not true process
>
> > I mean process.
>
> > Because it is a process not a thread.
>
> > Arne
>
> It's a thread, not a process.
Threads are, in essence, program counters. By this definition, if a
process's address space has exactly one program counter, that is a
single thread. If it has multiple program counters, it is multi-
threaded. Threads are also styled as lightweight processes.
UNIX has always had processes but threads came much later. Various
implementations of threads have been added to various UNIX
implementations. For example, this reference <http://linas.org/linux/
threads-faq.html> says the Linux kernel got the clone() system call in
release 1.3.56, though there were user mode implementations for Linux
before that.
It is instructive to compare clone() with fork().
If you want a new process in Linux (or any UNIX) you call fork(),
which creates a new private address space and an initial program
counter and other state variables. The new process is called the
child. It gets a copy of the calling process's instruction and data
space, so the child is in most respects a copy of its parent. Notable
exceptions are the process ID and the fork() return code. Typically
you put a condition after the fork() which tests the return code and
sends each process in a different direction.
If you want a new thread in Linux you call clone(), which does not
create an address space or copy instructions or data. It creates a new
program counter within the existing process. You pass clone() a
subroutine entry point, which is the starting point of execution for
the new thread, and you pass it the location of some free memory the
thread can use as a new execution stack. When the subroutine returns,
the thread is discarded.
Now. When a shell command (other than a built-in) is executed in the
typical manner, the shell calls fork() as above. Predictably, this
creates a new process which is a copy of the calling shell. The child
then calls exec(), which loads new executable code and data from the
desired executable file on disk. The shell executable code and data in
the child are overwritten. The child goes on its merry way. The parent
is still a shell. It commonly waits for the child to exit before
reading the next shell command, or it can be told not to wait
(somewhat like SPAWN/NOWAIT).
Alternatively, you can tell the shell not to bother with the fork(),
by prefixing the command with the "exec" keyword. In that case the
shell simply calls exec(), causing the shell itself to be overwritten
with the new executable code and data. The process ID is the same, but
the shell is gone, replaced by the new command. The exit status code
of the process will be that of the new command.
Best wishes,
Edward
More information about the Info-vax
mailing list