This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: OT: possible project/research project -- ksh has it all and is now available for cygwin
- From: "Karsten Fleischer" <Karsten dot Fleischer at gmx dot de>
- To: <cygwin at cygwin dot com>
- Date: Fri, 22 Mar 2002 02:39:10 +0100
- Subject: RE: OT: possible project/research project -- ksh has it all and is now available for cygwin
- Organization: Omnium Software Engineering
- Reply-to: <K dot Fleischer at omnium dot de>
Hi,
ksh93 is capable of keeping specially prepared executables as builtins.
Below is a copy of a mail I just got from the AT&T research labs with
some comments on how to implement such things, and a link where you can
download ksh93 source and binaries (yes, Cygwin binaries).
Please follow the instructions in their site carefully, it's not the
usual "./configure; make" thing, but it's not too hard to grasp ;-)
Karsten
---
warning: information on non-GNU software follows
from http://www.kornshell.com/doc/faq.html:
IV. SHELL EXTENSIONS
Q2. What is the advantage of making commands built-in?
A2. The startup time is reduced by a couple of orders of
magnitude. In addition, built-in commands can access
ksh internals.
Q3. What is the disadvantage of making commands built-in?
A3. Errors in these built-ins can cause the shell to crash.
Q4. How do I add built-in commands?
A4. There are two ways to do this. One is write a shared library
with functions whose names are b_xxxx, where xxxx is the name
of the builtin. The function b_xxxx takes three arguments: the
first two are the same as main(), and the third is a pointer
argument which will point to the current shell context. The
second way is to write a shared library with a function named
lib_init(). This function will be called with an argument of 0
after the library is loaded. This function can add built-ins
with the sh_addbuiltin() API function. In both cases, the
library is loaded into the shell with the "builtin" utility.
this mechanism has been in place since 1995
converting a standalone command to a builtin takes care:
exit(2) calls are not allowed
all resources must be painstakingly freed before returning
ksh is distributed with the libcmd library that contains candidate
builtins:
basename cmp dirname head mkdir rev tee
cat comm expr id mkfifo rm tty
chgrp cp fmt join mv rmdir uname
chmod cut fold ln paste stty uniq
chown date getconf logname pathchk tail wc
the standalone commands are also linked against libcmd, so the builtin
and standalone versions have exactly the same implementation no code in
libcmd uses the ksh API
example cygwin timings for non-builtin and builtin { mkdir rmdir} show
that the differences are not insignificant:
(cygwin) ksh -c '
time for ((i=1;i<=100;i++))
do
/bin/mkdir foo
/bin/rmdir foo
done'
real 0m32.87s
user 0m11.38s
sys 0m20.87s
(cygwin) ksh -c '
builtin -f cmd mkdir rmdir
time for ((i=1;i<=100;i++))
do
mkdir foo
rmdir foo
done'
real 0m0.54s
user 0m0.12s
sys 0m0.42s
and $(...) works as expected:
(cygwin) ksh -c '
x=
time for ((i=1;i<=100;i++))
do
x=$x$(/bin/basename /a/b/c)
done'
real 0m17.43s
user 0m5.83s
sys 0m10.86s
(cygwin) ksh -c '
builtin -f cmd basename
x=
time for ((i=1;i<=100;i++))
do
x=$x$(/bin/basename /a/b/c)
done'
real 0m0.20s
user 0m0.06s
sys 0m0.12s
ksh93 source and binaries are available at
http://www.research.att.com/sw/download/
at minimum you need the INIT and ast-ksh packages
the posted binaries were built on cygwin 1.3.7
on cygwin the builtin shared library is named cygcmd10.dll
(ksh does the cmd => cygcmd10.dll mapping)
so are fork/exec and spawn history? -- no
could a shell builtin dll fill a niche similar to a module in perl? --
yes
-- Glenn Fowler <gsf@research.att.com> AT&T Labs Research, Florham Park
NJ --
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/