CONTENTS Title Page Copyright Page Preface 1 Introduction to VMS POSIX 1.1 Using This Guide and the VMS POSIX Documentation 1.1.1 How to Use This Guide 1.1.2 Other Parts of the VMS POSIX Documentation 2 Comparing the POSIX and VMS Environments 2.1 Issues for All VMS POSIX Users 2.1.1 The VMS and VMS POSIX Environments 2.1.1.1 Determining the Environment 2.1.2 Moving Between the VMS and POSIX Environments 2.1.2.1 Moving from the VMS Environment to the POSIX Environment 2.1.2.2 Moving from the POSIX Environment to the VMS Environment 2.1.2.3 Creating a POSIX Session in a DECwindows Environment 2.1.3 Using the Terminal in the POSIX Environment 2.1.3.1 Command Line Editing 2.1.3.2 Recalling Commands 2.1.3.3 Controlling Terminal Actions 2.1.4 Waiting for the VMS POSIX Prompt (Type-Ahead Issues) 2.2 Issues for Users Accustomed to the VMS Environment 2.2.1 Using VMS Features in the VMS POSIX Environment 2.2.2 Run-Time Libraries 2.2.2.1 Linking VMS POSIX Applications with DECwindows and Other Images Based on VAX C 2.2.2.2 Running a POSIX Application with DECwindows 2.2.2.3 Using the Proper Header Files 2.2.3 Differences in C Language Functions 2.2.4 Security: File Access and Protection 2.2.5 Commands in the POSIX Environment 2.2.6 Processes in the POSIX Environment 2.3 Issues for Users Accustomed to the UNIX Environment 2.3.1 Programming Environment 2.3.2 Communication Interfaces 2.3.3 Online Help ( man ) 3 The VMS POSIX Programming Environment 3.1 Language Support in VMS POSIX 3.2 Program Development 3.2.1 Compiling a VMS POSIX Program 3.2.2 Defining the Proper Environment 3.2.2.1 Defining the _POSIX_SOURCE Macro 3.2.2.2 Using the Correct Header Files 3.2.2.3 Compiling Programs from the VMS POSIX Shell 3.2.3 Linking a Program 3.2.3.1 Linking a POSIX Application with DECwindows and Other VAX C Applications 3.2.4 Running a POSIX Program 3.2.4.1 Running a POSIX Program from DCL Level 3.2.4.2 Running a POSIX Program from the VMS POSIX Shell 3.2.5 Using the VMS Debugger 3.2.6 Summary of Program Development 3.3 Other Programming Considerations 3.3.1 Processes in VMS POSIX 4 File Systems in VMS POSIX 4.1 VMS and POSIX File System Differences 4.1.1 Directory Hierarchies 4.1.2 Filenames and Pathnames 4.1.2.1 Absolute Pathnames 4.1.2.2 Relative Pathnames 4.1.2.3 How Pathnames and the File Systems Interact 4.1.2.4 How POSIX Pathnames and VMS File Specifications Differ 4.1.3 File Structures 4.1.4 File Protection 4.1.4.1 VMS File Protection 4.1.4.2 POSIX File Protection 4.1.5 Special Files 4.1.6 Links Between Files 4.1.7 Symbolic Links 4.2 The VMS File System 4.2.1 When to Use the VMS File System 4.2.2 Modifying VMS File System Characteristics 4.2.3 Displaying VMS File System Characteristics 4.2.4 Referencing Files in the VMS File System 4.3 The Container File System 4.3.1 When to Use the Container File System 4.4 Using the VMS and Container File Systems 4.4.1 Using Valid Pathnames in VMS POSIX 4.4.1.1 How the VMS and Container File Systems Are Configured 4.4.1.2 Displaying Current VMS and Container File System Bindings 5 The VMS POSIX Shell 5.1 Overview of the VMS POSIX Shell 5.1.1 VMS POSIX Shell Files 5.1.1.1 The VMS POSIX Shell Script 5.1.1.2 The VMS POSIX Profile File 5.1.1.3 Special Files and Directories Required by VMS POSIX 5.1.2 Configuration Values 5.2 Invoking the VMS POSIX Shell 5.2.1 Moving from the VMS POSIX Shell to DCL 5.2.2 Using VMS POSIX Processes 5.2.2.1 Running Commands in the Foreground 5.2.2.2 Running Commands in the Background 5.2.2.3 Manipulating Background Jobs 5.2.3 Exiting from the VMS POSIX Shell 5.3 Using VMS POSIX Commands 5.3.1 Redirecting Input, Output, and Error Messages 5.3.2 Using Pipelines to Create Compound Commands 5.3.3 Grouping Commands into Lists 5.3.3.1 Creating Sequential Lists 5.3.3.2 Creating Asynchronous Lists 5.3.3.3 Creating AND Lists 5.3.3.4 Creating OR Lists 5.3.4 Using the Grouping Operators to Create Compound Commands 5.3.5 Working with Commands in the VMS POSIX Container 5.3.5.1 Using the ln Utility 5.4 Using Variables and Parameters in the Shell 5.4.1 Setting Variables 5.4.1.1 Displaying Shell Variables 5.4.1.2 Environment Variables 5.4.1.3 Exporting Variables 5.4.1.4 Using Operators to Manipulate Variables 5.4.2 Passing Variable Values to Shell Scripts 5.4.3 Using Special Parameters to Obtain Information About the Shell 5.5 Using the VMS POSIX Special Characters 5.5.1 Using Quoting Characters to Remove the Special Meanings Within the Shell 5.5.1.1 Using Single Quotes and Double Quotes with Positional Parameters 5.5.1.2 Removing the Quote Characters 5.5.2 Matching Characters, Strings, and Expressions in VMS POSIX 5.5.2.1 Using the Pattern Matching Notation 5.5.2.2 Using the Regular Expression (RE) Notation and the Extended Regular Expression (ERE) Notation 5.6 Expanding a VMS POSIX Shell Command Line 5.6.1 Alias Substitution 5.6.2 Expanding the Tilde Character 5.6.3 Expanding Parameters and Variables 5.6.4 Processing Substrings of a Parameter 5.6.5 Substituting Commands Within a Command Line 5.6.6 Arithmetic Expansion 5.6.7 Splitting the Fields in a Command Line 5.6.8 Expanding Pathnames 5.7 Coding a VMS POSIX Shell Script 5.7.1 Creating Interactive Scripts 5.8 Testing Conditions Within a Shell Script 5.8.1 Other Uses for the test Utility 5.8.2 Combining Test Expressions 5.8.3 Testing the Exit Status 5.9 Using Reserved Words to Control the Flow of Command Execution 5.9.1 Using the Conditional Statements 5.9.1.1 Using the if Conditional 5.9.1.2 Using the case Conditional 5.9.2 Looping Within a Shell Script 5.9.2.1 Using the for Loop 5.9.2.2 Using the while Loop 5.9.2.3 Using the until Loop 5.9.3 Nesting Control Structures 5.9.4 Controlling Command Execution 5.10 Creating Shell Functions 5.10.1 Returning Values from a Function 6 Real-Time Programming 6.1 Process Synchronization 6.1.1 Creating and Using Binary Semaphores 6.1.1.1 Binary Semaphore Special Files and VAXcluster Configurations 6.1.1.2 Persistent and Nonpersistent Binary Semaphores 6.1.1.3 Posting and Waiting for Semaphores 6.1.1.4 What Is a P Operation? 6.1.1.5 What Is a V Operation? 6.1.1.6 Removing a Binary Semaphore 6.1.2 Clocks and Timers 6.1.2.1 Creating Relative and Absolute Timers 6.1.2.2 Creating Periodic and One-Shot Timers 6.1.2.3 Setting the Systemwide Clock 6.1.2.4 Disabling Timers 6.1.2.5 Delivery of Timer Events 6.1.3 Priority Scheduling 6.1.3.1 FIFO Scheduling Policy 6.1.3.2 Round-Robin Scheduling Policy 6.1.3.3 OTHER Scheduling Policy 6.1.3.4 Setting Scheduling Policies and Priorities 6.2 Interprocess Communication 6.2.1 Event Notification 6.2.1.1 Signals and Event Classes 6.2.1.2 What Are Event Class Masks? 6.2.1.3 How Are Events Raised? 6.2.2 Message Queues 6.2.2.1 Creating a Message Queue Special File 6.2.2.2 Message Queue Special Files and VAXcluster Configurations 6.2.2.3 How an Application Can Be Configured 6.2.2.4 Sending Messages 6.2.2.4.1 Copying Data 6.2.2.4.2 Moving Data 6.2.2.4.3 Using Data 6.2.2.5 Receiving Messages Selectively 6.2.2.6 Message Queue Attributes 6.2.2.7 Purging Messages from the Queue 6.2.2.8 Removing a Message Queue 6.2.3 Shared Memory 6.2.3.1 Creating and Referencing a Shared Memory File 6.2.3.2 Shared Memory Special Files and VAXcluster Configurations 6.2.3.3 Persistent and Nonpersistent Shared Memory 6.2.3.4 Mapping and Unmapping Shared Memory 6.2.3.5 Linking, Unlinking, and Closing Shared Memory 6.3 Performance 6.3.1 Process Memory Locking 6.3.1.1 Determining Process Working Set Size 6.3.1.2 Automatic Memory Locking 6.3.1.3 Locking Units 6.3.2 Synchronized Input and Output 6.3.2.1 What Is Synchronized I/O File and Data Integrity? 6.3.2.2 Flushing Pending Operations 6.3.3 Asynchronous Input and Output 6.3.4 Real-Time Files 6.3.4.1 Increment Lists 6.3.4.2 File System Capabilities and File Attributes 7 Application Portability 7.1 Portability in the POSIX Environment 7.1.1 Application Conformance 7.1.1.1 The Agreement 7.1.1.2 Conformance Levels 7.1.1.3 Implementation-Defined, Undefined, and Unspecified Behaviors 7.1.2 Application Design Considerations 7.1.2.1 The Key Design Issue: Knowing the Target Environment 7.1.2.2 Other Design Issues 7.1.3 Programming Considerations 7.1.3.1 Programming for Portability in POSIX-General Guidelines 7.1.3.2 Programming for Portability in POSIX: Data Types, Structures, and Pointers 7.2 General Issues Related to Writing Portable Programs 7.2.1 Defining Portability 7.2.2 General Principles of Portability 7.2.3 Portability Issues 7.2.4 Writing Modular Code 7.2.4.1 Porting Programs 7.2.4.2 Example of Porting Code 7.2.4.3 Using Modules and Abstraction 7.2.4.3.1 Procedural Abstraction 7.2.4.3.2 Data Abstraction 7.2.4.3.3 Object-Oriented Programming 7.2.4.4 Practical Recommendations 7.2.5 General Coding Guidelines 7.2.5.1 Coding Modules by Function 7.2.5.2 Identifying and Isolating System Dependencies 7.2.5.3 Using the Common Subset of Language and Run-Time Features 7.2.5.4 Writing Strongly Typed Code 7.2.5.5 Writing Explicit Code 7.2.5.6 Leaving Optimization to the Compiler 7.2.5.7 Understanding and Using Target Platforms 7.2.5.8 Determining and Understanding Target Audiences 7.2.5.9 Centralizing Shared Definitions 7.2.5.10 Following Good Coding Practices 8 Comparing the VMS POSIX Callable Interface to Other Systems 8.1 Comparing the System V and the VMS POSIX Callable Interfaces 8.2 Comparing the BSD System and the VMS POSIX Callable Interfaces 8.3 Comparing the ULTRIX and the VMS POSIX Callable Interfaces 8.4 Comparing VMS RTL Routines to the VMS POSIX Callable Interface A POSIX Commands POSIX/RUN POSIX/SHOW B VMS POSIX Sample Application B.1 Program XMPL.C B.1.1 Subprogram ADB.C B.1.2 Subprogram DE.C B.1.3 Subprogram DR.C B.1.4 Subprogram EL.C B.1.5 Subprogram MENU.C B.1.6 Subprogram WD.C B.2 Building Procedure for the VMS POSIX Sample Application B.2.1 build_me.com File B.2.2 build_script. File B.2.3 driver2.c File B.2.4 makefile_dot2. File B.2.5 makefile_driver2. File FIGURES 1-1 Portability: The Open Systems Concept 4-1 Absolute Pathname TABLES 2-1 Terminal Control Keys in VMS POSIX 2-2 Commands with the Same Name in DCL and VMS POSIX 2-3 Comparison of UNIX cc Options and VAX C Compiler Qualifiers 5-1 VMS POSIX Symbolic Constants 5-2 Redirection Operators 5-3 VMS POSIX Environment Variables 5-4 Assignment Operator 5-5 Mathematical Operators 5-6 Bit Operators 5-7 Comparison Operators 5-8 Special Parameters 5-9 Special Characters 5-10 Quoting Characters 5-11 Wildcard Characters 5-12 Aliases Built in to the Shell 5-13 Parameter Expansions 5-14 Expansion of Parameter Substrings 5-15 Testing the Characteristics of a File 5-16 Comparing the Age of Two Files 5-17 Comparing the Values of Numbers 5-18 Comparing the Values of Strings 5-19 Reserved Words for VMS POSIX 6-1 POSIX and VMS Priority Mapping 8-1 Comparing System V Base System Functions to VMS POSIX Functions 8-2 Comparing BSD System Interface Functions to VMS POSIX Functions 8-3 Comparing ULTRIX System Interface Functions to VMS POSIX Functions 8-4 Comparing VMS Run-Time Library Routines to VMS POSIX Functions