Windows NT 4.0 comes with several subsystems included in the default installation. These subsystems are POSIX, OS/2, and Windows Debug. In this Daily Feature, I’ll discuss the POSIX subsystem and how you can begin using it to run UNIX commands that have been ported to NT 4.0.
About POSIX and subsystems
POSIX (Portable Operating System Interface for Computing Environments) is a standard initially defined in 1990 to promote making applications portable across UNIX-based operating systems. The POSIX subsystem supports POSIX file structure, POSIX calls, and executables such as chmod, cat, and ls. A subsystem, within the context of Windows NT 4.0, is literally just that, a system that runs under the Windows NT 4.0 shell. A shell, in any operating system, refers to the part of the program that is the user interface. You may already be familiar with the MS-DOS command prompt, a text-based shell for typing commands in Windows NT 4.0.
Subsystems allow system and software developers to implement some very basic functionality for the subsystem in question. For example, the OS/2 subsystem supports a number of OS/2 API calls. In POSIX, this support is accomplished through the use of a Korn shell, which the NT 4.0 system references as sh.
For those of you familiar with the UNIX or Linux operating systems, you will find the commands noted above to be quite familiar. For example, ls is a command similar to DIR, the DOS directory command. Users can view or change file attributes such as read, write, and execute with chmod. The command used in DOS is attrib.
POSIX under NT 4.0
For all intents and purposes you may assume that the POSIX subsystem itself already exists on your NT 4.0 system. If there is any doubt, look in your Winnt\system32 directory for an executable called psxss.exe. This executable, the POSIX subsystem server, is one of the three files necessary to run the POSIX subsystem. The other two files are posix.exe and psxdll.dll. These files are called automatically any time you run a POSIX command.
As you might have guessed, POSIX implementation under Windows NT 4.0 is rudimentary. POSIX applications, for example, have no access to the Win32 subsystem, such as dynamic data exchange, networking, or graphics calls. Nor can POSIX applications (without being redirected) print or call any DLL files or any Windows NT 4.0 programs. POSIX works best with the NTFS file system, which supports POSIX file system features such as hard links and case-sensitive file names. POSIX applications can be started from the command prompt, the Run command, My Computer, or Windows Explorer.
While the default installation of Windows NT 4.0 does include the POSIX subsystem, it does not include any basic POSIX utilities. To add these utilities (Microsoft provides eighteen binary utilities under the Gnu Public Licensing Agreement or GPL), you will need to purchase the Microsoft NT 4.0 Workstation Resource Kit.
The precompiled binary utilities that Microsoft provides as part of the Resource Kit distribution are, in fact, Win32 POSIX clones and include:
- cat—concatenates and prints files
- cp—a copy command
- ls—a directory lister
- mv—the move/rename command
- touch—a utility to change file timestamps
- wc—a counter for words, lines, bytes, or characters
- vi—a text editor
The remaining POSIX utilities provided by Microsoft require you to initially use a Microsoft development environment of some sort and include, among other things, a POSIX-compliant version of a C-Language compiler (cc), linker (ln), and an archiving utility (ar).
If you prefer to use something other than the Resource Kit or if you feel that the Resource Kit is too outdated, there are alternatives, such as the vast collection of precompiled POSIX-compliant binary utilities available on the Internet, either as a single distribution or as part of a larger tool set such as Cygwin or MinGW. AT&T Research has a product available called UWIN, which is available free to researchers and educators.
All of these POSIX subsystems are useable and functional under the Win32api-based operating systems and will allow you to build and/or implement POSIX-compliant utilities or applications.
POSIX in action
Once you’ve installed POSIX utilities from one of the sources mentioned above, all you need to do to run a POSIX command is start the command prompt by selecting Start | Programs | Command Prompt, then type the command. Make sure you give the correct path for which you might have to use the DOS directory name. For example, if the command ls were in Program Files, you might have to type progra~1\ls. Figure A shows the result of using the ls.exe command. If you’re familiar with UNIX or Linux, you’ll recognize the output of the command running under Windows NT 4.0 as identical to the versions you’ve seen elsewhere.
|The ported ls command lists files just like its UNIX and Linux counterparts.|
If you’ve installed one of the more fully featured POSIX subsystems, you’ll essentially be able to run UNIX within NT. Figure B shows the AT&T Korn shell, or ksh, operating in a console window under its UWIN distribution. Note the prompt ($). This figure shows the output of several typical UNIX commands. The first, ps, lists running processes. The second, pwd, shows the current directory. Note that the forward slash (/) is being used instead of the Windows backslash (\). The third, cd, moves to the /home directory. Finally, fourth and fifth, two versions of the ls command are shown. The first version lists files and directories without details, and the second, using the –l option, shows file and directory details.
|By using a third-party POSIX subsystem such as AT&T’s UWIN, you can run a full-fledged Korn shell and take advantage of its many utilities and applications.|
The POSIX subsystem of Windows NT 4.0 gives advanced NT users a taste of UNIX in NT. However, the subsystem is rudimentary. For those wishing to port UNIX applications to NT 4.0, to develop UNIX scripts and programs within an NT environment, or simply to use the capabilities UNIX has to offer, third-party tools expand the subsystem into a true, rich UNIX shell.
The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.