OSS Programmers Guide
OSS Programmers Guide
The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express
warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP
shall not be liable for technical or editorial errors or omissions contained herein.
Export of the information contained in this publication may require authorization from the U.S. Department of Commerce.
Microsoft, Windows, and Windows NT are U.S. registered trademarks of Microsoft Corporation.
Intel, Pentium, and Celeron are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other
countries.
Motif, OSF/1, UNIX, X/Open, and the "X" device are registered trademarks, and IT DialTone and The Open Group are trademarks of The Open
Group in the U.S. and other countries.
Open Software Foundation, OSF, the OSF logo, OSF/1, OSF/Motif, and Motif are trademarks of the Open Software Foundation, Inc. OSF MAKES
NO WARRANTY OF ANY KIND WITH REGARD TO THE OSF MATERIAL PROVIDED HEREIN, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. OSF shall not be liable for errors contained
herein or for incidental consequential damages in connection with the furnishing, performance, or use of this material.
© 1990, 1991, 1992, 1993 Open Software Foundation, Inc. The OSF documentation and the OSF software to which it relates are derived in part
from materials supplied by the following:© 1987, 1988, 1989 Carnegie-Mellon University. © 1989, 1990, 1991 Digital Equipment Corporation. ©
1985, 1988, 1989, 1990 Encore Computer Corporation. © 1988 Free Software Foundation, Inc. © 1987, 1988, 1989, 1990, 1991 Hewlett-Packard
Company. © 1985, 1987, 1988, 1989, 1990, 1991, 1992 International Business Machines Corporation. © 1988, 1989 Massachusetts Institute of
Technology. © 1988, 1989, 1990 Mentat Inc. © 1988 Microsoft Corporation. © 1987, 1988, 1989, 1990, 1991, 1992 SecureWare, Inc. © 1990, 1991
Siemens Nixdorf Informationssysteme AG. © 1986, 1989, 1996, 1997 Sun Microsystems, Inc. © 1989, 1990, 1991 Transarc Corporation.OSF software
and documentation are based in part on the Fourth Berkeley Software Distribution under license from The Regents of the University of California.
OSF acknowledges the following individuals and institutions for their role in its development: Kenneth C.R.C. Arnold, Gregory S. Couch, Conrad
C. Huang, Ed James, Symmetric Computer Systems, Robert Elz. © 1980, 1981, 1982, 1983, 1985, 1986, 1987, 1988, 1989 Regents of the University
of California.
Table of Contents
About This Document.......................................................................................................15
About TNS, TNS/R Native, and TNS/E Native Processes....................................................................15
About the Examples..............................................................................................................................15
About OSS Utilities...............................................................................................................................15
Supported Release Version Updates (RVUs)........................................................................................16
Intended Audience................................................................................................................................16
New and Changed Information............................................................................................................16
Changes made to the 520674-014 Edition........................................................................................16
Changes made to the 520674-013 Edition........................................................................................16
Changes made to the 520674-012 Edition........................................................................................17
Changes Made to the 520674-011 Edition........................................................................................17
Changes Made to the 520674-010 Edition........................................................................................17
Changes Made to the 520674-009 Edition........................................................................................17
Changes Made to the 520674-008 Edition........................................................................................17
Changes Made to the 520674-007 Edition........................................................................................18
Document Organization.......................................................................................................................18
Notation Conventions...........................................................................................................................19
General Syntax Notation.................................................................................................................19
Related Information..............................................................................................................................21
Publishing History................................................................................................................................23
HP Encourages Your Comments..........................................................................................................24
Table of Contents 3
Using the HP Enterprise Toolkit - NonStop Edition.............................................................................49
2 Managing Files............................................................................................................51
The OSS and Guardian File Systems....................................................................................................51
Physical and Logical Names............................................................................................................51
Filename and Pathname Mappings.................................................................................................52
Obtaining Corresponding Guardian and OSS Filenames...............................................................54
Using Guardian Procedures............................................................................................................55
OSS File-Access Permissions...........................................................................................................60
Safeguard Protection and Disk Volumes.........................................................................................61
OSS ACLs.........................................................................................................................................61
Accessible Files................................................................................................................................62
Using the ANSISTREAMS Pragma (Guardian C Program)............................................................62
Common and Unique Characteristics...................................................................................................62
Features Common to the UNIX and OSS File Systems...................................................................62
Features Unique to the OSS File System.........................................................................................62
Accessing Files From the OSS API........................................................................................................63
Using Functions With Environment-Specific Parameters...............................................................64
Accessing Files From the Guardian API...............................................................................................65
Guardian Procedure Extensions for OSS.........................................................................................65
Using Extended Guardian Procedures............................................................................................69
Accessing OSS Files Larger Than 2 GB.................................................................................................74
Small Files and Large Files..............................................................................................................74
Large File Safe APIs.........................................................................................................................75
Large File Aware APIs.....................................................................................................................76
Interoperability................................................................................................................................77
Common Completion...........................................................................................................................79
Performance Considerations.................................................................................................................82
File Caching.....................................................................................................................................82
Performance and Reliability Tradeoffs............................................................................................84
OSS File-System Functions...................................................................................................................84
Guardian File-System Procedures........................................................................................................94
3 Managing Processes....................................................................................................97
Common and Unique Characteristics...................................................................................................97
Features Common to UNIX and OSS Process Management...........................................................97
Features Unique to OSS Process Management..............................................................................105
Process Attributes...............................................................................................................................105
OSS Attributes in Guardian Processes..........................................................................................105
Guardian Attributes in OSS Processes..........................................................................................105
Comparing OSS and Guardian Process Attributes.......................................................................106
Process-Management Interoperability................................................................................................107
Signals Interoperability..................................................................................................................110
Creating and Controlling Processes....................................................................................................111
Using the OSS API.........................................................................................................................111
Using the Guardian API................................................................................................................115
Querying the Process Environment....................................................................................................121
Using the OSS API.........................................................................................................................121
Using the Guardian API................................................................................................................122
Modifying the Process Environment..................................................................................................127
Using the OSS API.........................................................................................................................127
Using the Guardian API................................................................................................................128
Performance Considerations...............................................................................................................130
4 Table of Contents
Using Dynamic Servers Spread Across Available Processors.......................................................130
Using Static Servers Spread Across Available Processors.............................................................134
OSS Process-Management Functions..................................................................................................141
Guardian Process-Management Procedures.......................................................................................146
5 Managing Time.........................................................................................................155
Common and Unique Characteristics.................................................................................................155
Features Common to UNIX and OSS Time Management.............................................................155
Features Unique to OSS Time Management..................................................................................156
Time-Management Interoperability....................................................................................................156
Querying the System Clock................................................................................................................156
Querying Process Times......................................................................................................................157
Limiting Processor Time Use..............................................................................................................157
OSS Time-Management Functions.....................................................................................................157
Guardian Time-Management Procedures..........................................................................................160
6 Interprocess Communication....................................................................................163
Available Methods..............................................................................................................................163
Common and Unique Characteristics.................................................................................................164
Features Common to UNIX and OSS Interprocess Communication............................................164
Features Unique to OSS Interprocess Communication.................................................................165
Interprocess-Communication Interoperability...................................................................................165
Using Guardian AF_INET and AF_NET6 Sockets, and OSS AF_INET and AF_INET6 Sockets...165
Using AF_UNIX Sockets.................................................................................................................176
Using FIFOs...................................................................................................................................178
Using Guardian Shared Memory and Semaphores......................................................................178
Using the $RECEIVE File...............................................................................................................179
Performance Considerations...............................................................................................................183
OSS Interprocess-Communication Functions.....................................................................................184
Guardian Interprocess-Communication Procedures..........................................................................191
7 Managing I/O...........................................................................................................195
Common and Unique Characteristics.................................................................................................195
Features Common to UNIX and OSS Terminal I/O Management................................................195
Features Unique to OSS Terminal I/O Management.....................................................................195
I/O Interoperability.............................................................................................................................195
Table of Contents 5
Tape I/O...............................................................................................................................................196
Tape I/O With pax .........................................................................................................................196
Tape I/O With the Guardian API...................................................................................................197
Terminal I/O........................................................................................................................................198
Accessing Terminals From the OSS Environment.........................................................................198
Blocking and Nonblocking Opens.................................................................................................199
Blocking and Nonblocking Terminal I/O.......................................................................................199
Terminal Parameters......................................................................................................................199
Control Characters.........................................................................................................................199
Accessing Terminals From the Guardian Environment................................................................200
Using OSSTTY to Redirect Input and Output to Guardian Objects...................................................202
Starting OSSTTY............................................................................................................................203
Examples of OSSTTY Usage..........................................................................................................205
Printer I/O...........................................................................................................................................214
Printing With the OSS API.............................................................................................................214
Printing OSS Files With the Guardian API....................................................................................215
OSS I/O Management Functions.........................................................................................................221
Guardian I/O Management Procedures..............................................................................................222
Table of Contents 7
Example Program Using Reentrant Functions..............................................................................315
Thread-Aware Toolkit Functions and Types.................................................................................316
Using Thread-Aware Toolkit Functions........................................................................................317
Caveats to Using the Thread-Aware Toolkit .................................................................................320
Thread-Aware $RECEIVE I/O Functions.......................................................................................320
Using Thread-Aware $RECEIVE Functions..................................................................................321
Caveats to Using Thread-Aware $RECEIVE.................................................................................324
Thread-Aware Enscribe Functions......................................................................................................324
Using Thread-Aware Enscribe Functions......................................................................................325
OSS File Descriptor and Timer Callbacks...........................................................................................326
Using OSS and Timer Callbacks....................................................................................................327
Caveat to Using Callbacks.............................................................................................................327
8 Table of Contents
Thread-Aware Enscribe Functions......................................................................................................370
Using Thread-Aware Enscribe Functions......................................................................................371
OSS File Descriptor and Timer Callbacks...........................................................................................372
Using OSS and Timer Callbacks....................................................................................................373
Caveat to Using Callbacks.............................................................................................................373
Converting Applications that use the SPT Library.............................................................................373
Build Scripts...................................................................................................................................374
Header Files...................................................................................................................................374
Standard and Nonstandard Pthread Types...................................................................................375
Global Variables.............................................................................................................................375
Concurrency Level Defaults..........................................................................................................375
Differences in Functions and Function Behavior..........................................................................375
Threaded Application Programming.................................................................................................378
Keeping Application Design Simple.............................................................................................378
Threading Considerations.............................................................................................................378
Single Versus Multiple Application Threads.................................................................................381
Threaded Application Examples...................................................................................................382
Glossary.........................................................................................................................515
Index...............................................................................................................................523
Table of Contents 9
List of Figures
1-1 The Operating Environment for NonStop Systems......................................................................26
1-2 OSS Filenames and Disks..............................................................................................................28
1-3 Components of Guardian File Names...........................................................................................29
1-4 Guardian File Names and Disks...................................................................................................30
1-5 Guardian Files in the OSS File System..........................................................................................31
7-1 OSSTTY Interaction With OSS and Guardian Environments.....................................................203
10-1 Major Components and Interfaces for OSS Security Management.............................................241
10 List of Figures
List of Tables
1 Related Manuals............................................................................................................................22
1-1 OSS and Guardian Process Identifiers .........................................................................................32
1-2 Sample c89 Commands ................................................................................................................44
2-1 OSS Pathname to Guardian Filename Translation Examples.......................................................53
2-2 Guardian Filename to OSS Pathname Translation Examples ......................................................53
2-3 Mappings of Guardian Security to OSS File-Access Permissions ................................................60
2-4 I/O Buffering, Fault Tolerance, and Performance.........................................................................83
2-5 OSS File-System Functions ...........................................................................................................85
2-6 Guardian File-System Procedures ................................................................................................94
3-1 OSS and Guardian Process Attribute Comparison ....................................................................106
3-2 Guardian Process-Management Procedures That Can Access OSS Processes ..........................107
3-3 OSS Process-Management Functions That Can Access Guardian Processes .............................108
3-4 OSS Process-Management Functions..........................................................................................141
3-5 Guardian Process-Management Procedures...............................................................................147
4-1 OSS Memory Management Functions.........................................................................................152
4-2 Guardian Memory Management Functions................................................................................153
5-1 Guardian and OSS Timestamps .................................................................................................156
5-2 OSS Time-Management Functions .............................................................................................159
5-3 Guardian Time-Management Procedures ..................................................................................161
6-1 Interprocess Communication Using OSS APIs...........................................................................163
6-2 Interprocess Communication Using OSS and Guardian APIs ...................................................164
6-3 OSS Interprocess-Communication Functions.............................................................................185
6-4 OSS Interprocess-Communication-Related Functions................................................................188
6-5 Guardian Interprocess-Communication Procedures..................................................................191
6-6 Guardian Interprocess-Communication-Related Procedures.....................................................193
7-1 Canonical Mode Control Characters and Associated Flags in termios.h ...................................200
7-2 Noncanonical Mode Control Characters and Associated Flags in termios.h ............................200
7-3 OSS I/O Functions........................................................................................................................221
7-4 Guardian I/O Procedures............................................................................................................223
8-1 OSS Logging Functions ..............................................................................................................226
8-2 OSS Logging Function Parameters and Default Values .............................................................227
8-3 Logging Level Event Numbers and Strings ...............................................................................228
8-4 openlog() Parameters Used by OSS Logging Mechanism ..........................................................228
8-5 OSS Logging Facilities ................................................................................................................228
8-6 OSS Logging Options .................................................................................................................229
8-7 OSS Logging Function Parameters and Corresponding EMS Tokens .......................................232
8-8 OSS Logging-Mechanism Functions...........................................................................................232
10-1 OSS Security-Related Functions .................................................................................................241
10-2 OSS Function Calls Audited When Used With Audited filesets ................................................243
10-3 Guardian Procedure Calls Audited When Used With Audited filesets ....................................245
10-4 Guardian Procedure Calls Audited When Used for Process Control ........................................245
10-5 Base ACL Entries.........................................................................................................................252
10-6 Actual (Nondefault) Optional ACL Entries................................................................................252
10-7 Default ACL Entries....................................................................................................................253
11-1 Process Resources........................................................................................................................261
11-2 Attributes of Standard POSIX Threads Defined by Macros........................................................263
11-3 Signals Processed by Threads......................................................................................................264
11-4 Numerical Limits in Standard POSIX Threads ..........................................................................275
11-5 Comparison of spt_*, spt_*x, and spt_*z Functions...........................................................291
11-6 System and Equivalent Thread-Aware Functions ......................................................................292
11-7 System and Equivalent Reentrant Functions ..............................................................................314
11
11-8 Thread-Aware Toolkit Functions and Types...............................................................................317
11-9 Thread-Aware $RECEIVE Functions and Types.........................................................................321
11-10 Thread-Aware Enscribe Functions .............................................................................................324
11-11 Thread-Aware Callback Functions and Types............................................................................327
12-1 Attributes of the POSIX User Thread Model Library Defined by Macros..................................331
12-2 Process Resources........................................................................................................................332
12-3 Numerical Limits in the POSIX User Thread Model Library .....................................................333
12-4 Signals Processed by Threads......................................................................................................334
12-5 System and Equivalent Thread-Aware Functions ......................................................................346
12-6 Thread-Aware Toolkit Functions and Types...............................................................................361
12-7 Thread-Aware $RECEIVE Functions and Types.........................................................................365
12-8 Thread-Aware Enscribe Functions .............................................................................................370
12-9 Thread-Aware Callback Functions and Types............................................................................373
12-10 Standard header files included in spthread.h and pthread.h header files..................................374
12-11 SPT Library Nonstandard Types and Corresponding PUT Model Library Standard Types.....375
12-12 Nonstandard pthread_ functions replaced by standard versions............................................376
B-1 API Interoperability in TNS Processes........................................................................................431
C-1 API Interoperability in Native Processes (Functions a through m)............................................457
C-2 API Interoperability in Native Processes (Functions n through z).............................................478
12 List of Tables
List of Examples
1-1 Using Some OSS Group Information Functions...........................................................................33
1-2 Calling a Guardian Procedure That Returns a Return Value .......................................................37
1-3 Calling a Guardian Procedure That Returns a Condition Code ..................................................39
1-4 Specifying the systype Option to the c89 Utility...........................................................................41
1-5 Linking Guardian Modules to OSS Programs..............................................................................41
1-6 Using gtacl to Run a TACL Command..........................................................................................42
1-7 Using gtacl to Pipe TACL Command Output to an OSS Utility...................................................42
1-8 Starting the Inspect or Native Inspect Debugger by Itself............................................................46
1-9 Starting the Inspect or Native Inspect Debugger and a Program at the Same Time....................46
1-10 Starting the Visual Inspect Debugger............................................................................................47
1-11 Convert Type 180 File to Type 101 File..........................................................................................47
1-12 Convert Type 101 File to Type 180 File..........................................................................................47
2-1 Using gname to Obtain a Guardian Filename..............................................................................54
2-2 Using pname to Obtain an OSS Pathname....................................................................................55
2-3 FUP INFO DETAIL Display With an OSS File..............................................................................55
2-4 Using the Guardian PATHNAME_TO_FILENAME_ Procedure.................................................56
2-5 Using the Guardian FILENAME_TO_PATHNAME_ Procedure.................................................57
2-6 Using FILE_COMPLETE_SET, FILE_COMPLETE_, and FILE_COMPLETE_GETINFO_ ..........58
2-7 Reading a Guardian File With an OSS Function Call ...................................................................64
2-8 Using fopen_guardian() in an OSS Module..................................................................................65
2-9 Reading an OSS File in Nowait Mode With Guardian Procedures .............................................67
2-10 Reading an OSS File With Guardian Procedures .........................................................................69
2-11 Using a Guardian Procedure to Get OSS File Information by Name ..........................................71
2-12 Using a Guardian Procedure to Get OSS File Information by Number .......................................73
2-13 Using select() on FIFOs...........................................................................................................80
3-1 Dynamic Launcher Program ........................................................................................................99
3-2 Dynamic Echo Server Program ..................................................................................................102
3-3 Determining and Changing Process Priority using getpriority() and nice() ..............................104
3-4 Creating an OSS Process Using tdm_fork() and tdm_execvep() ................................................112
3-5 Creating an OSS Process Using tdm_spawnp() .........................................................................114
3-6 Creating and Controlling a Guardian Process Using Guardian Procedures .............................116
3-7 Creating an OSS Process Using PROCESS_SPAWN_ ................................................................119
3-8 Getting Information About System Limits Using sysconf() .......................................................122
3-9 Getting Information About a Process Using PROCESS_GETINFO_ .........................................124
3-10 Getting Information About a Process Using PROCESS_GETINFOLIST_ .................................126
3-11 Setting the User ID of the Current Process Using setuid() .........................................................128
3-12 Modifying Information About the Current Process Using PROCESS_SETINFO_ and
PROCESS_SETSTRINGINFO_ ..................................................................................................129
3-13 Dynamic Launcher Program to Spawn Dynamic Server ...........................................................132
3-14 Launcher Program to Spawn Static Servers ...............................................................................135
3-15 Static Echo Server .......................................................................................................................139
5-1 Using SETLOOPTIMER in an OSS Program...............................................................................157
5-2 Using gettimeofday()...................................................................................................................159
6-1 Using AF_INET in an OSS Server Process..................................................................................168
6-2 Using AF_INET in an OSS Requester Process.............................................................................171
6-3 Using AF_INET in a Guardian Server Process............................................................................174
6-4 Using $RECEIVE in an OSS Server Process................................................................................180
6-5 Using $RECEIVE in an OSS Requester Process...........................................................................182
7-1 Using the pax Utility From a Program .......................................................................................197
7-2 Accessing an OSS Terminal With Guardian Procedures in the OSS API ...................................201
7-3 Example Logger Program Used With OSSTTY ..........................................................................207
13
7-4 Running an Interactive OSS Session From the Guardian Environment ....................................211
7-5 Printing an OSS File With the lp Utility .....................................................................................215
7-6 Sending an OSS File to the Guardian Spooler.............................................................................217
7-7 Sending an OSS File Directly to a Printer Using the Guardian API ...........................................220
8-1 Calling syslog() With Formatting Codes ....................................................................................230
8-2 Calling syslog() With the %m Formatting Code ........................................................................230
8-3 Use of System Logging Functions ..............................................................................................231
10-1 Using OSS Security Functions ....................................................................................................247
10-2 Using acl() and aclsort()....................................................................................................259
11-1 Handling the Synchronous Signal SIGFPE.................................................................................268
11-2 Handling the Synchronous Signal SIGINT.................................................................................270
11-3 Handling the SIGCHLD Signal...................................................................................................272
11-4 Handling SIGALRM Signals.......................................................................................................274
11-5 Threaded Time-of-Day Server Socket .........................................................................................284
11-6 Threaded Time-of-Day Server Socket Using $RECEIVE.............................................................287
11-7 File Stream Thread-Aware Function Usage.................................................................................297
11-8 File Descriptor Thread-Aware Function Usage...........................................................................297
11-9 Open File Descriptor Thread-Aware Function Usage.................................................................297
11-10 Pthreads Nonblocking Disk File I/O (SPT_THREAD_AWARE_NONBLOCK version) ............299
11-11 Pthreads Thread-Aware Disk File I/O Using SPT_THREAD_AWARE_XNONBLOCK ............309
11-12 Using the Reentrant Function strtok_r........................................................................................316
11-13 Thread-Aware Toolkit Program Flow.........................................................................................318
11-14 Simplified Program Flow For a Thread-Aware Function............................................................318
11-15 Thread-Aware read() Function....................................................................................................318
11-16 Nonblocking Thread-Aware read() Function..............................................................................319
11-17 Example READX() Function Used In Thread-Aware Manner....................................................320
11-18 Thread-Aware $RECEIVE Program Flow...................................................................................321
11-19 Function with spt_RECEIVEREAD() and spt_REPLYX()............................................................322
11-20 $RECEIVE Server.........................................................................................................................323
11-21 Using the Thread-Aware SPT_FILE_OPEN Function.................................................................326
11-22 OSS File Descriptor Callback.......................................................................................................327
11-23 Timer Callback Program Flow....................................................................................................327
12-1 Handling the Synchronous Signal SIGFPE.................................................................................339
12-2 Handling the Synchronous Signal SIGINT.................................................................................341
12-3 Handling the SIGCHLD Signal...................................................................................................342
12-4 Handling SIGALRM Signals.......................................................................................................344
12-5 File Stream Thread-Aware Function Usage.................................................................................348
12-6 File Descriptor Thread-Aware Function Usage...........................................................................348
12-7 Open File Descriptor Thread-Aware Function Usage.................................................................349
12-8 Pthreads Thread-Aware Disk File I/O Using PUT Model Library..............................................350
12-9 Using the Reentrant Function strtok_r........................................................................................360
12-10 Thread-Aware Toolkit Program Flow.........................................................................................362
12-11 Simplified Program Flow For a Thread-Aware Function............................................................362
12-12 Nonblocking Thread-Aware read() Function..............................................................................363
12-13 Example READX() Function Used In Thread-Aware Manner....................................................364
12-14 Thread-Aware $RECEIVE Program Flow...................................................................................365
12-15 Function with put_RECEIVEREAD() and put_REPLYX()..........................................................366
12-16 $RECEIVE Server.........................................................................................................................367
12-17 Using the Thread-Aware PUT_FILE_OPEN Function................................................................372
12-18 OSS File Descriptor Callback.......................................................................................................373
12-19 Timer Callback Program Flow....................................................................................................373
12-20 Threaded Time-of-Day Server Socket .........................................................................................383
12-21 Threaded Time-of-Day Server Socket Using $RECEIVE.............................................................386
14 List of Examples
About This Document
The Open System Services Programmer’s Guide describes how to write application programs in C
for the OSS environment. This guide includes information about:
• How the OSS environment differs from the standard UNIX programming environment
• When you need to use the Guardian application program interface (API) in OSS C programs
• Which tasks can be performed only from the Guardian or OSS API
• Performance considerations
The basics of how to program in a UNIX environment are well documented in commercial texts
and are not an objective of this guide. Please refer to the following books for information about
programming in a UNIX environment.
• Advanced Programming in the UNIX Environment, W. Richard Stevens, Addison-Wesley, 1992.
• Multithreaded Programming with Pthreads, Bill Lewis and Daniel J. Berg, Sun Microsystems
Press, 1998.
• POSIX Programmer’s Guide, Donald Lewine, O’Reilly and Associates, Inc., 1991.
• Practical UNIX & Internet Security, Simon Garfinkel and Gene Spafford, O’Reilly and
Associates, Inc., 1996.
• Pthreads Programming, Bradford Nichols, Dick Buttlar, and Jacqueline Proulx Farrell, O’Reilly
and Associates, Inc., 1996.
• UNIX Network Programming, 2nd Edition, W. Richard Stevens, Prentice-Hall, 1997.
Intended Audience
This guide is intended for intermediate and advanced C application programmers who write
programs for the OSS environment. Experience with programming in a UNIX environment is
assumed.
16
Changes made to the 520674-012 Edition
These new functions were added to the discussion of jacket routines in Chapter 11 (page 261),
Appendix A (page 389), and Appendix C (page 451):
spt_INITRECEIVEL()
spt_RECEIVEREADL()
spt_REPLYXL()
SPT_SERVERCLASS_SENDL_()
The complete list of jacket routines has been added to Appendix A (page 389).
These new functions were added to Table 3-3 (page 108)Table 3-3, OSS Process-Management
Functions That Can Access Guardian Processes, on page 3-16, Table 10-1 (page 241)Table 10-1,
OSS Security- Related Functions, on page 10-4, Appendix A (page 389), and Appendix C (page 451):
initgroups()
setegid()
seteuid()
setgroups()
Document Organization
This guide contains the following sections and appendixes:
• Chapter 1: Overview of the OSS Programming Environment (page 25) introduces the OSS
and Guardian file systems and process types, discusses how to select source and target
environments, describes how to call OSS functions and Guardian procedures and functions
in OSS programs, and indicates the programming tools available.
• Chapter 2: Managing Files (page 51) describes how to use the OSS file system, including
manipulating OSS regular files and Guardian disk files, and nowait I/O.
• Chapter 3: Managing Processes (page 97) describes process management, including managing
OSS and Guardian processes, using the HP extension functions, getting information about
processes, and modifying the process environment.
• Chapter 4: Managing Memory Segments (page 149) describes how the concept of memory
management differs among the UNIX, Guardian, and OSS environments.
• Chapter 5: Managing Time (page 155) describes time management, including querying the
system clock, querying process times, and limiting processor usage.
• Chapter 6: Interprocess Communication (page 163) describes the mechanisms processes can
use to communicate with one another within the same processor, between processors, and
between nodes in a HP NonStop network.
18
• Chapter 7: Managing I/O (page 195) describes how to manage OSS tape, terminal, and printer
I/O.
• Chapter 8: Using Logging Mechanisms (page 225) describes how to log information in the
OSS environment.
• Chapter 9: Using Subsystems From OSS (page 235) mentions any special considerations or
limitations in using HP subsystems from OSS application programs.
• Chapter 10: Managing OSS Security (page 239) lists and provides a short description of the
OSS security features.
• Chapter 11: Using the Standard POSIX Threads Library (page 261) describes the Standard
POSIX Threads product available for C and C++ in the OSS environment.
• Appendix A: Documented OSS Functions (page 389) lists all OSS functions in the current
release and gives information such as where they are documented.
• Appendix B: API Interoperability in TNS Processes (page 427) describes the interoperability
between the OSS and Guardian APIs in TNS processes.
• Appendix C: API Interoperability in Native Processes (page 451) describes the interoperability
between the OSS and Guardian APIs in native processes.
In some cases, you will need to consult the Guardian Programmer’s Guide while writing OSS
application programs. The organization of this guide is very similar to the organization of the
Guardian Programmer’s Guide, so that you can easily make the transition from one programmer’s
guide to the other.
Notation Conventions
General Syntax Notation
This list summarizes the notation conventions for syntax presentation in this manual.
UPPERCASE LETTERS
Uppercase letters indicate keywords and reserved words. Type these items exactly as shown.
Items not enclosed in brackets are required. For example:
MAXATTACH
Italic Letters
Italic letters, regardless of font, indicate variable items that you supply. Items not enclosed
in brackets are required. For example:
file-name
Computer Type
Computer type letters indicate:
• C and Open System Services (OSS) keywords, commands, and reserved words. Type
these items exactly as shown. Items not enclosed in brackets are required. For example:
Use the cextdecs.h header file.
• Text displayed by the computer. For example:
Last Logon: 14 May 2006, 08:02:23
• A listing of computer code. For example
if (listen(sock, 1) < 0)
{
perror("Listen Error");
exit(-1);
}
Bold Text
Bold text in an example indicates user input typed at the terminal. For example:
Notation Conventions 19
ENTER RUN CODE
?123
CODE RECEIVED: 123.00
The user must press the Return key after typing the input.
[ ] Brackets
Brackets enclose optional syntax items. For example:
TERM [\system-name.]$terminal-name
INT[ERRUPTS]
A group of items enclosed in brackets is a list from which you can choose one item or none.
The items in the list can be arranged either vertically, with aligned brackets on each side of
the list, or horizontally, enclosed in a pair of brackets and separated by vertical lines. For
example:
FC [ num ]
[ -num ]
[ text ]
K [ X | D ] address
{ } Braces
A group of items enclosed in braces is a list from which you are required to choose one item.
The items in the list can be arranged either vertically, with aligned braces on each side of the
list, or horizontally, enclosed in a pair of braces and separated by vertical lines. For example:
LISTOPENS PROCESS { $appl-mgr-name }
{ $process-name }
ALLOWSU { ON | OFF }
| Vertical Line
A vertical line separates alternatives in a horizontal list that is enclosed in brackets or braces.
For example:
INSPECT { OFF | ON | SAVEABEND }
… Ellipsis
An ellipsis immediately following a pair of brackets or braces indicates that you can repeat
the enclosed sequence of syntax items any number of times. For example:
M address [ , new-value ]…
- ] {0|1|2|3|4|5|6|7|8|9}…
An ellipsis immediately following a single syntax item indicates that you can repeat that
syntax item any number of times. For example:
"s-char…"
Punctuation
Parentheses, commas, semicolons, and other symbols not previously described must be typed
as shown. For example:
error := NEXTFILENAME ( file-name ) ;
LISTOPENS SU $process-name.#su-name
Quotation marks around a symbol such as a bracket or brace indicate the symbol is a required
character that you must type as shown. For example:
"[" repetition-constant-list "]"
Item Spacing
Spaces shown between items are required unless one of the items is a punctuation symbol
such as a parenthesis or a comma. For example:
20
CALL STEPMOM ( process-id ) ;
If there is no space between two items, spaces are not permitted. In this example, no spaces
are permitted between the period and any other items:
$process-name.#su-name
Line Spacing
If the syntax of a command is too long to fit on a single line, each continuation line is indented
three spaces and is separated from the preceding line by a blank line. This spacing
distinguishes items in a continuation line from items in a vertical list of selections. For example:
ALTER [ / OUT file-spec / ] LINE
[ , attribute-spec ]…
Related Information
Table 1 shows the programming guides, reference manuals, and user guides that contain
information related to the information in this guide.
Related Information 21
Table 1 Related Manuals
22
• Guardian Programmer’s Guide. This guide describes how to access the Guardian API using
Guardian procedure calls. It is written for application and system programmers.
• Open System Services Porting Guide. This guide describes conversion techniques for moving
existing C-language applications into the OSS environment. It discusses both C-language
and operating system considerations. This guide is intended for application programmers,
with some information for selected operating system users.
• Software Internationalization Guide. This guide describes how to use the OSS
internationalization features. It is written for application and system programmers.
The following are related reference manuals:
• Guardian Procedure Calls Reference Manual. This manual describes the syntax for most Guardian
procedure calls. It is intended for system and application programmers.
• Guardian Native C Library Calls Reference Manual. This manual describes syntax and semantics
of the native C run-time library calls and header files for the Guardian environment. This
manual is intended for system and application programmers.
• Guardian TNS C Library Calls Reference Manual. This manual describes syntax and semantics
of the TNS C run-time library calls and header files for the Guardian environment. This
manual is intended for system and application programmers.
• Open System Services Library Calls Reference Manual. This manual describes syntax and
semantics of the C run-time library calls and header files for the OSS environment. This
manual is intended for system and application programmers.
• Open System Services Shell and Utilities Reference Manual. This manual presents rules and
syntax for each command that the user enters interactively to access the OSS command
interpreter (called the shell), and utilities and other functions that perform general-purpose
and program-development operations. It is written for all audiences: system administrators,
managers, and operators; end users; and application and system programmers.
• Open System Services System Calls Reference Manual. This manual describes all OSS system
calls (file system and kernel functions), their syntax, required external data structures,
resulting operations, and source file (header) locations for all literals and symbolic definitions.
It is written for application and system programmers.
The following are related user guides:
• Guardian User’s Guide. This guide provides basic information about the programs and utilities
that are used most often in the Guardian environment by general system and application
users. It also provides more detailed procedures for system operations, management, and
maintenance tasks that are useful to both beginning and experienced users of HP NonStop
systems.
• Open System Services User’s Guide. This guide provides basic orientation, tutorial, and task
information for using the OSS shell and utilities. It is written for all audiences: system
administrators, managers, and operators; end users; and application and system
programmers.
Publishing History
Part Number Product Version Publication Date
Publishing History 23
HP Encourages Your Comments
HP encourages your comments concerning this document. We are committed to providing
documentation that meets your needs. Send any errors found, suggestions for improvement, or
compliments to [email protected].
Include the document title, part number, and any comment, error found, or suggestion for
improvement you have concerning this document.
24
1 Overview of the OSS Programming Environment
OSS is an alternative to the Guardian interface through which users and programs can interact
with the HP NonStop operating system. OSS interfaces and functions greatly resemble those of
UNIX systems in general, because of their common relationship to the POSIX standards. OSS
adds to the UNIX API by offering access to Guardian fundamentals and interoperability with
the Guardian environment by offering extensions to the standard API, additional OSS function
calls, and access to Guardian procedure calls.
OSS provides:
• A basis for middleware products. OSS supports a variety of middleware software, such as
the HP NonStop Tuxedo, NonStop Distributed Object Manager/MP (DOM), and NonStop
Server for Java products, that might also be used in an application.
• An open interface to the operating system for supporting portable applications.
This guide focuses on the latter function: writing applications in C for the OSS target execution
environment without the use of middleware. For your convenience, Chapter 9: Using Subsystems
From OSS (page 235) contains a brief overview of some of the middleware available for NonStop
systems. For more information on such middleware, refer to the manual set for the specific
software product in which you are interested.
The OSS programming environment allows you to access Guardian objects and subsystems as
well as OSS objects. OSS accomplishes this interoperability between environments using standard
library and system function calls, and HP extensions to these calls and to Guardian procedures.
This section discusses the following topics:
Topic Content
“The OSS API” (page 25) Relationship to the Guardian API and the NonStop
operating system, and conformance to industry standards.
“Two File Systems” (page 27) Basic differences between the OSS and Guardian file
systems, including directory structures, file access, and
file types.
“Two Process Types” (page 31) Basic differences between the OSS and Guardian
processes, including process identifiers, groups, ancestors,
attributes, and pairs.
“Selecting Source and Target Execution Environments” Typical source and target execution environments and
(page 34) exceptions to the typical case.
“Calling Functions and Procedures in OSS Programs” How to call OSS functions and Guardian functions and
(page 35) procedures and when to use them.
“Using the Development Tools” (page 41) Available editors, development utilities, compilers,
linkers, optimizers, debuggers, and performance
analyzers.
“Using the HP Enterprise Toolkit - NonStop Edition” An integrated development environment that enables
(page 49) you to build applications on a PC.
An application program can be compiled to run in either the OSS or Guardian environment and
can use services from each environment, including the API, tools, and utilities.
Standards Conformance
The OSS API conforms to the POSIX.1 and POSIX.2 standards, and partially conforms to the
XPG4 specifications. These standards and specifications are described in the following documents:
• Information Technology – Portable Operating System Interface (POSIX) – Part 1: System Application
Program Interface (API) [C Language], ISO/IEC 9945-1 (IEEE Std 1003.1, SH13680), First Edition
1990.
• Information Technology – Portable Operating System Interface (POSIX) – Part 2: Shell and Utilities,
ISO/IEC 9945-2 (IEEE Std 1003.2a), First edition 1992.
• X/Open CAE Specifications – System Interfaces and Headers, Issue 4.
• X/Open CAE Specifications – System Interfaces and Headers, Issue 4, Version 2.
Conformance to POSIX.1
You might need to write applications that strictly conform to a certain standard or specification.
A strictly-conforming POSIX.1 application cannot use any of the following:
• Any function unique to a NonStop system, such as tdm_fork(), that is an extension to the
standard.
• The Guardian environment. This is not discussed by the standard.
• A Guardian object. This is not discussed by the standard.
• A remotely mounted fileset. This is not discussed by the standard.
• A symbolic link. This is not discussed by the current version of the standard.
• A POSIX.2 function, such as those provided in the regex.h and glob.h header files.
• An XPG4 function, such as those provided in the fnmatch.h, nl_types.h, and wchar.h
header files.
• An XPG4 function that is an extension to standard header files, such as getw() in stdio.h.
• Any function related to OSS access control lists (ACLs)
Open System Services manages the directory tree using filesets. A fileset is a directory tree that
can be mounted or unmounted. Most literature about UNIX refers to filesets as file systems. In
the OSS and Guardian environments, the term file system also refers to the software that manages
the file system.
OSS files and directories are designated by pathnames. A pathname is the string of characters
that uniquely identifies a file within its file system. A pathname can be either relative or absolute.
An absolute pathname starts with a slash (/) and begins at the root directory. A relative pathname
does not start with a slash and begins with the current working directory. The PATH_MAX symbolic
constant in the limits.h header file defines how long OSS pathnames can be.
A directory or fileset can occupy many disk volumes. Pathnames are logical names. They have
no relationship to disk volumes, as shown in Figure 1-2. A file cannot occupy more than one disk
volume. Refer to the pathname(5) reference page either online or in the Open System Services
System Calls Reference Manual.
File Types
Open System Services supports these file types:
• Regular files (disk files)
• Directories
• FIFOs/pipes
• Sockets
• Symbolic links
• Character special files (Only /dev/tty terminal character files and /dev/null)
All OSS regular (data) files are odd-unstructured files. OSS regular files can be accessed using
Guardian functions and procedures as well as OSS functions.
Guardian file names visible to an OSS program are physical names: they refer to physical objects.
A node name refers to a physical node, and a volume name refers to a physical disk volume. A
node cannot contain nodes, a volume cannot contain volumes, and a subvolume cannot contain
subvolumes. The relationship between Guardian file names and physical devices is shown in
Figure 1-4.
Guardian files on the local node appear as OSS files in the /G directory of the OSS file system.
The local node name is omitted.
Guardian files on remote NonStop nodes also appear as OSS files in the /E directory of the OSS
file system. The pathnames for such files begin with /E/nodename and continue with the /G
directory on the indicated node. For example:
/E/node2/G/volume/subvol/fileid
Figure 1-5 shows the Guardian file /G/volume1/subvol1/myfile in the OSS file system.
File Types
Using OSS functions, you can read and write only odd-unstructured Guardian files. EDIT files
are unstructured files, and you can access them only for reading. OSS functions cannot access
structured Guardian files (SQL, entry-sequenced, key-sequenced, and relative). You can access
structured Guardian files using Guardian procedure calls in an OSS program.
File Access
Guardian file access is determined by the RWEP character string. This is a four-character string;
the positions determine who can Read, Write, Execute, or Purge a file (hence RWEP). For further
information about Guardian file security, refer to the Guardian User’s Guide.
Process Identification
Table 1-1 shows the ways in which OSS processes and Guardian processes can be identified.
Processes always have “required” identifiers, never have identifiers that are “not available,” and
might have those classified as “optional.” You can specify optional identifiers when you call
process-creation procedures or functions.
Table 1-1 OSS and Guardian Process Identifiers
Process Identifier OSS Process Guardian Process
The following list defines the OSS and Guardian process identifiers:
OSS process ID
Uniquely identifies an OSS process within a node.
Process handle
Uniquely identifies an OSS or Guardian process within a NonStop network.
Process name
Name containing 1 to 5 alphanumeric characters preceded by a dollar sign ($).
Process Groups
An OSS process can belong to a process group, which is identified by a group ID. Processes in
the same group can be treated collectively; for example, all processes in a group that are active
at the same time can receive the same job control signals. Therefore, when you enter a command
from the OSS shell to suspend a job, all processes in the group associated with that job can receive
the signal to stop. (Signals can be sent to an individual process or to an entire process group.)
A Guardian process cannot belong to a process group or session, which is a collection of one or
more process groups.
Example 1-1 provides code to demonstrate the use of some of the OSS group information functions
including getgrent(), endgrent(), setgrent(), getgrgid(), and getgrnam().
Process Attributes
All processes, OSS and Guardian, have Guardian attributes and some OSS attributes. OSS
processes have additional OSS-specific attributes, such as an OSS process ID. Open System
Services includes standard UNIX functions such as the fork() function and the exec set of
functions as well as HP extension functions, which are tdm_fork(), tdm_execve(),
tdm_execvep(), tdm_spawn(), and tdm_spawnp(). The HP extension functions allow you
to set attributes when a process is created that you cannot set with standard UNIX functions.
For example, when you create a new OSS process image with the execve() function, the new
process retains many attributes of the calling process, and you cannot overwrite them in the call
to execve(). The tdm_execve() function allows you to either retain the caller’s attributes or
specify other values. For example, you can change the attribute specifying the processor in which
a process executes.
Process Environment
The run-time environment of an OSS process is defined using environment variables. A Guardian
process uses PARAMs, ASSIGNs, and DEFINEs to define its environment, but a Guardian process
also has environment variables if it is created using Guardian C functions.
Process Pairs
A Guardian process can belong to a process pair, which consists of a primary process that performs
the application and a secondary (backup) process in another processor that is ready to take over
if the primary process fails. Process pairs provide one way in which you can create fault-tolerant
applications. You implement process pairs using Guardian checkpointing procedures.
An OSS process cannot belong to a process pair, and you cannot call Guardian checkpointing
procedures from OSS programs.
OSS Functions
Use OSS functions wherever possible, even to manipulate Guardian objects. For example, if you
want to open a Guardian file that is odd-unstructured, use the OSS open() function. Call OSS
functions as you would any standard C function.
OSS functions are defined in library header files in the /usr/include directory. For detailed
information about OSS functions, see the following manuals:
• Library functions (those in logical section 3 of the reference pages) are described in the Open
System Services Library Calls Reference Manual.
• System functions (those in logical section 2 of the reference pages) are described in the Open
System Services System Calls Reference Manual.
• The HP C language for NonStop systems, run-time library, and compiler information are
described in the C/C++ Programmer’s Guide.
Guardian Procedures
You can (and in some cases must) use Guardian procedures when you cannot accomplish a task
with OSS functions. For example, to get the file code of a Guardian file, you must use a Guardian
file system procedure, such as FILE_GETINFO_ or FILE_GETINFOBYNAME_. You also might
want to use Guardian procedures in cases where the Guardian procedure provides more
information. For example, FILE_GETINFOLIST_ provides much more information than the
stat() function about Guardian or OSS files.
char *filename;
short typeinfo[5];
Note 1
The cextdecs.h library header file contains function prototype declarations for Guardian
procedures you can call directly from a C program. It is important to specify which Guardian
procedures the program will call; otherwise, all function prototype declarations in
cextdecs.h are included in your program. In this program, only the function prototype
declaration for the FILE_GETINFOBYNAME_ procedure is included.
To use cextdecs.h with a native program, you must specify the EXTENSIONS pragma,
because the procedure declarations in cextdecs.h use _tal syntax instead of the pragma
function syntax.
Note 2
The integer into which a value is returned, retcode, is declared as a short integer. This is
because the integer data type in Guardian procedures represents a 16-bit word, while the
integer data type in OSS C programs represents a 32-bit word.
/* Read from the file and check for valid condition code. */
CC = READX( filenum, /* file number */
buffer, /* buffer address */
1024, /* size of buffer */
&bytesread, /* number of bytes read */
);
if(_status_ne(CC)) { /* if condition code indicates an error */
fprintf(stderr, "Read error, bytes read = %d\n", bytesread);
exit(1);
}
Note 1
The tal.h library header file must be included when you call Guardian procedures that
return condition codes.
Guardian C Functions
The native C run-time library supports both the OSS and Guardian environments, which means
that there is a single library for functions that are part of both APIs. Most differences that exist
in behavior of the functions in the two APIs for TNS programs no longer exist for native programs.
For information about interoperability between the Guardian and OSS APIs in native processes,
see Table C-1: API Interoperability in Native Processes (Functions a through m) (page 457).
There are a few functions that are specified by HP and can be called only from a Guardian module,
which means you must call them from a separate module compiled for the Guardian environment.
For information on these functions, see the Open System Services Library Calls Reference Manual
or the Guardian Native C Library Calls Reference Manual.
The result of Example 1-4 is an object file named gprog.o. Example 1-5 compiles the main OSS
program and links it with the Guardian C module object file into an executable program file
named outfile.
The operations shown in Example 1-4 and Example 1-5 cannot be combined into one c89
command. You must use two c89 commands, because you cannot compile two modules with
different systype values in the same c89 command.
For some basic examples of how to use the c89 and c99 utilities, see “Using the Development
Tools” (page 41) and for more detail, refer to C/C++ Programmer’s Guide and to the c89(1) or
the c99(1) utility reference page either online or in the Open System Services Shell and Utilities
Reference Manual.
gtacl Utility
Using the gtacl utility is another way to mix development environments. gtacl runs a process
in the Guardian environment from the OSS environment and lets you use Guardian tools from
the OSS shell. You can use gtacl to start an interactive TACL process, execute a single Guardian
environment command, or run a Guardian environment program. Example 1-6 uses gtacl to
run the TACL STATUS command.
You can also pipe (send) the output of a Guardian command or program to an OSS utility.
Example 1-7 pipes the output of the TACL FILES command to the OSS grep utility.
Example 1-7 Using gtacl to Pipe TACL Command Output to an OSS Utility
$ gtacl -c 'files' | grep -c 'tdm'
When using gtacl, keep in mind that block-mode applications, such as TEDIT and Pathway,
require 6530 terminal emulation. 6530 terminal emulation is available only in the Guardian
environment, which means that block mode applications are not accessible through gtacl.
For more information about gtacl, refer to the Open System Services User’s Guide and to the
gtacl(1) utility reference page either online or in the Open System Services Shell and Utilities
Reference Manual.
OSSTTY
OSSTTY provides a way for OSS processes to interact with Guardian processes using the OSS
standard files. Using OSSTTY, an OSS process can redirect its standard files (stdin, stdout,
stderr) to a Guardian process or to a Guardian EDIT file. For example, the following command
uses OSSTTY to redirect the stdin of the OSS child process to $vhs, and the stdout to $zhome:
TACL> osh/ in $vhs, out $zhome/ -osstty
For more information on using OSSTTY, see Chapter 7 (page 195). A complete description of the
osstty command options is given in the Open System Services Management and Operations Guide.
OSS Tools
The following tools are available to you from the OSS environment at the OSS shell prompt. If
you provide your own tools, be aware that OSS environment tools run faster as compiled programs
than as OSS shell scripts.
C Development Utilities
Open System Services provides a variety of tools to assist you in developing C applications. The
following are some of the more useful programming tools:
• ar, which creates and maintains groups of one or more named files as a single library file
written in an archive format. If the archive contains object files, the archive can be used as
an object file library by the Binder. For detailed information, refer to the ar(1) utility
reference page either online or in the Open System Services Shell and Utilities Reference Manual.
• lex, which allows you to create structured input analyzers. You provide regular expressions
that specify what you want to find in the input stream and lex generates a C language
lexical analyzer from these rules that provides tokens for your application. The lex utility
is often used in conjunction with yacc, which parses the stream of tokens that the lexical
analyzer produces. For detailed information, refer to the Open System Services User’s Guide
and to the lex(1) utility reference page either online or in the Open System Services Shell
and Utilities Reference Manual.
• make, which maintains program dependencies. The make utility is useful in combining your
program modules into a coherent application and enabling you to maintain individual
modules. For detailed information, refer to the Open System Services User’s Guide and to the
make(1) utility reference page either online or in the Open System Services Shell and Utilities
Reference Manual.
• nm, which lists symbolic information appearing in an object file, executable file, or object-file
library. For detailed information, refer to the nm(1) utility reference page either online or
in the Open System Services Shell and Utilities Reference Manual.
• strip, which removes any information not required for executing files. Do not use strip
before using the symbolic debuggers, because strip removes the symbol region required
for symbolic debugging. For detailed information, refer to the strip(1) utility reference
page either online or in the Open System Services Shell and Utilities Reference Manual.
• yacc, which enables you to generate parsing programs. This utility is useful if, for example,
your application has an input language. You supply a grammar for the language, and yacc
produces a C program that parses the input stream. The yacc utility is often used in
conjunction with lex, from which it receives tokens. For detailed information, refer to the
Open System Services User’s Guide and to the yacc(1) utility reference page either online or
in the Open System Services Shell and Utilities Reference Manual.
Compilation Tools
The c89 and c99 utilities control the C compilation system in the OSS environment. There are
native versions of c89 and c99 for TNS/E systems, a native version of c89 for TNS/R systems,
and a TNS version of c89 for TNS/R systems. (A TNS version of c89 is not supported on TNS/E
systems). The native versions are the default versions. The c99 utility is supported for TNS/E
targets on TNS/E systems only.
c89 test1.c a.out • TNS/R target: Compiles, links (using the default
linker nld), produces non-PIC executable program
file.
• TNS/E target: Compiles, links (using the eld linker),
produces PIC (position-independent code)
executable program file.
c89 test1.c -Wcall_shared a.out Compiles, links (using the ld linker for TNS/R target,
or the eld linker for TNS/E target), produces
position-independent code (PIC) executable file.
c89 -c test1.c test1.o Compiles, does not link, produces object file.
c89 -o testout test1.c testout Compiles, links, produces executable program file.
c89 -o testout test1.o test2.c testout Compiles test2.c, links it with test1.o, produces
executable program file.
Topic Manual
c89 The C/C++ Programmer’s Guide and the c89(1) utility reference page either online or in the
Open System Services Shell and Utilities Reference Manual
c99 The C/C++ Programmer’s Guide and the c99(1) utility reference page either online or in the
Open System Services Shell and Utilities Reference Manual
nld The nld Manual and the nld(1) reference page either online or in the Open System Services
Shell and Utilities Reference Manual
ld The ld Manual and the ld(1) reference page either online or in the Open System Services
Shell and Utilities Reference Manual
noft The noft Manual and the noft(1) reference page either online or in the Open System Services
Shell and Utilities Reference Manual
eld The eld Manual and the eld(1) reference page either online or in the Open System Services
Shell and Utilities Reference Manual
enoft The enoft Manual and the enoft(1) reference page either online or in the Open System
Services Shell and Utilities Reference Manual
Example 1-9 starts the Inspect (on a TNS/R system) or Native Inspect debugger (on a TNS/E
system) and a program to be debugged at the same time, both from the TACL prompt and the
OSS shell.
Example 1-9 Starting the Inspect or Native Inspect Debugger and a Program at the Same Time
> RUND gprog
$ run -debug -inspect=on ossprog
For more information on the G-series Inspect debugger, see the Inspect Manual. If you are familiar
with dbx, a debugger commonly found on UNIX systems, see the Inspect Manual for a table
contrasting dbx and Inspect commands. For more information on the Native Inspect debugger,
see the Native Inspect Manual.
PC-Based Debuggers
NonStop Development Environment for Eclipse debugging
NSDEE Core with Debugging also includes a separately installed integrated debugger that you
can use to debug TNS/E processes. See “Using the NonStop Development Environment for
Eclipse” (page 49).
Visual Inspect
Visual Inspect is a PC-based interactive debugging tool that provides a graphical user interface
(GUI) in which you control the debug session and execute debugging commands through
pull-down menus and dialog boxes. Using Visual Inspect, you control the execution and
debugging of your program from a PC while the program runs on a NonStop server.
Visual Inspect supports high-level symbolic debugging of native and TNS processes (interpreted
and accelerated) in the Guardian and OSS environments through a PC-based graphical user
interface. Visual Inspect can also be used for debugging snapshot files.
Visual Inspect is supported on both G-series and H-series systems. G-series and H-series Visual
Inspect are identical, except that the H-series version has been enhanced with machine-level
debugging capabilities; you can use H-series Visual Inspect for low-level debugging tasks on
the PC that must be done on the NonStop server using Debug or Inspect on G-series systems.
Visual Inspect is the preferred debugger in the native environments. It offers a simpler and more
intuitive user interface and more capabilities compared to the command-line debuggers, and is
designed to work in complex distributed environments. For example, working from a PC, you
can use Visual Inspect to debug multiple processes residing on the same or on different nodes
in a network. The processes can be TNS, native TNS/R, or native TNS/E, in the Guardian or OSS
environment.
You can start Visual Inspect by entering the RUNV command, either at the TACL prompt or
from the OSS shell. The following example starts execution of a program under control of Visual
Inspect on the client PC mypc:
You can also start Visual Inspect by first establishing a client connection to Visual Inspect on a
PC, then entering a run command with -inspect=on. For example, assuming a Visual Inspect
client connection exists, the following command starts a program under control of Visual Inspect:
$ run -debug -inspect=on ossprog
Visual Inspect can also be started from within the Enterprise Toolkit - NonStop Edition (ETK)
PC-based program development environment (see “Using the HP Enterprise Toolkit - NonStop
Edition” (page 49) for more information).
See the Visual Inspect online help for more information on Visual Inspect.
Guardian Tools
The following tools are available to you from the Guardian environment at the TACL prompt.
Editor
TEDIT is a full-screen text editor. For information about TEDIT features and commands, see the
PS Text Edit and PS Text Format User’s Guide.
To convert a type 101 file to a type 180 file, use the EDITTOC conversion tool, as shown in
Example 1-12.
Note that files of type 180 do not have a concept of line numbers. Converting from file type 101
to 180 and back to 101 results in the loss of line number information.
Compilation Tools
There are two sets of native compilation tools and one set of TNS compilation tools:
• The TNS/R native compilation tools are the the TNS/R native C and C++ compilers, the ld
and nld utilities (linkers), and the noft utility for examining attributes of TNS/R native
object files. Control over code optimization is built into the compilers
• The TNS/E native compilation tools are the TNS/E native C and C++ compilers, the eld
utility (linker), and the enoft utility for examining attributes of TNS/E native object files.
Control over code optimization is built into the compilers.
• The TNS compilation tools are the TNS C compiler, Binder (linker), and Accelerator (optimizer
on systems running G-series RVUs) or Object Code Accelerator (optimizer on systems
running H-series RVUs). On systems running G-series RVUs, the TNS compilation tools are
supported in the OSS and Guardian environments. On systems running H-series RVUs, the
TNS compilation tools are supported only in the Guardian environment.
Debuggers
See the discussion about the Inspect, Native Inspect, NonStop Development Environment for
Eclipse (NSDEE), and Visual Inspect products in “OSS Tools” (page 42).
Topic Content
“The OSS and Guardian File Systems” (page 51) Differences between the two file systems, including
filename formats and mapping, and Guardian security
and OSS file-access permissions.
“Common and Unique Characteristics” (page 62) Summary of the differences between the OSS and UNIX
file systems.
“Accessing Files From the OSS API” (page 63) Discussion and examples of how to access files from the
OSS API.
“Accessing Files From the Guardian API” (page 65) Discussion and examples of how to access files from the
Guardian API.
“Accessing OSS Files Larger Than 2 GB” (page 74) Discussion of support for OSS files larger than
approximately 2 GB, including accessing such files from
OSS APIs and Guardian APIs, and interoperability issues.
“Common Completion” (page 79) An enhancement to the Enscribe file system and the Open
System Services file system.
“Performance Considerations” (page 82) Discussion of how to get optimum performance for your
application.
“OSS File-System Functions” (page 84) List of each OSS file-system function with notes about its
OSS implementation and use with Guardian files.
“Guardian File-System Procedures” (page 94) List of each Guardian file-system procedure that affects
or is affected by OSS files with notes about its use with
OSS files.
52 Managing Files
5. Slashes are replaced by periods. The final result is:
\NODE1.$DataVol.srcl1v348.properti
/G/data/mysubvol/file \NODE.$DATA.MYSUBVOL.FILE
/G/disk \NODE.$DISK
/G/ztnt/#pty7 \NODE.$ztnt.#pty7
Only filenames on the local node can appear in the /G directory, so only local names are translated.
OSS files are stored with Guardian filenames in subvolumes whose names begin with ZYQ. The
OSS absolute pathname that corresponds to a Guardian filename has the following form:
/G[/volume[/subvolume[/fileid]]]
The number of components of the translated pathname depends on the number of components
in the filename. The components of a pathname are derived from a filename as follows:
1. The filename is converted to lower case.
2. volume is derived by replacing the dollar sign ($) in the filename with /G/.
3. A period (.) in the filename is replaced with a slash (/) .
Table 2-2 shows pathnames that can be translated to valid OSS filenames and the corresponding
OSS filename.
Table 2-2 Guardian Filename to OSS Pathname Translation Examples
Guardian Filename OSS Pathname
$VOL /G/vol
$vol /G/vol
$VOL.SUBVOL /G/vol/subvol
$p.#1234 /G/p/#1234
$p.#PTY12 /G/p/#pty12
$pubs.henry.panaceas /G/pubs/henry/panaceas
$ gname -s test
\NODE.$VOL.ZYQ00000.Z0000DV3
$ gname /G/zznt/#pty00bk
gname: /G/zznt/#pty00bk --> \NODE.$ZZNT.#PTY00BK
To display the OSS pathname that corresponds to a Guardian filename, enter the following from
the OSS shell:
pname [-s] filename
where the -s flag displays only the OSS pathname and filename is a Guardian fully qualified
or system-qualified filename. Example 2-2 shows examples of using pname.
54 Managing Files
NOTE: As shown in Example 2-2, you must put a backslash (\) before the slash (/), the backslash
(\), and dollar sign ($) characters, or else the shell will interpret them with their special shell
meanings rather than as plain characters. You can also put the filename inside single quotation
marks.
$ pname \\node.\$VOL.ZYQ00000.Z0000DV3
pname: \node.$VOL.ZYQ00000.Z0000DV3 --> /home/henrysp/test
$ pname -s \$VOL.ZYQ00000.Z0000DV3
/home/henrysp/test
$ pname -s '$VOL.ZYQ00000.Z0000DV3'
/home/henrysp/test
In the figure, the OWNER field contains -1 because the owner is the super ID. For other owners,
the field contains the structured form (group_number, member_number) of the NonStop
operating system user ID. The structured form can be converted to the scalar form used as the
OSS user ID (UID) using the following formula:
UID = member_number + (256 * group_number).
char filename[64];
short filelen;
short status;
Example 2-5 shows how to use the FILENAME_TO_PATHNAME_ procedure. The program
takes as its input a Guardian filename and prints out the corresponding OSS pathname. This
program example demonstrates the use of /E.
56 Managing Files
Example 2-5 Using the Guardian FILENAME_TO_PATHNAME_ Procedure
Guardian FILENAME_TO_PATHNAME procedure */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h>
#include <cextdecs.h(FILENAME_TO_PATHNAME_)>
char pathname[PATH_MAX];
short pathlen;
short index = 0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tdmext.h>
#include <unistd.h>
#include <fcntl.h>
#include <zsysc>.h>
#include <tal.h>
#include <cextdecs.hh(FILE_OPEN_,READX,FILE_COMPLETE_,AWAITIOX,\
FILE_COMPLETE_SET_,FILE_COMPLETE_GETINFO_)>
_cc_status CC;
short filenum, fnum, bytesread;
int fd,nb;
short retcode, status;
char *pathname; /* OSS path name */
char *filename; /* Guardian file name */
char bufoss[1025]; /* allow for NULL character at end of OSS buffer */
char bufgdn[1025]; /* allow for NULL character at end of Guardian buffer */
zsys_ddl_complete_element_def comp_elem[2]; /* completion elements */
short err_elem; /* error return for FILE_COMPLETE_SET_ */
short num_elem; /* Total number of Guardian and OSS files */
zsys_ddl_completion_info_def comp_info; /* completion information */
zsys_ddl_complete_element_def info_list[7];
/* array of information elements */
58 Managing Files
/* Set the completion elements for the OSS file and the Guardian file */
comp_elem[0].z_fnum_fd = fd; /* OSS file */
comp_elem[0].u_z_options.z_options.z_filetype = 1;
comp_elem[0].u_z_options.z_options.z_read_ready = 1;
comp_elem[0].u_z_options.z_options.z_exception = 1;
comp_elem[1].z_fnum_fd = filenum; /* Guardian file */
comp_elem[1].u_z_options.z_options.z_filetype = 0;
status = FILE_COMPLETE_SET_((short *) comp_elem, 2, &err_elem);
if(status) {
if(err_elem)
fprintf(stderr, "Error %d in FILE_COMPLETE_SET for OSS file = \
%s\n", err_elem, pathname);
else
fprintf(stderr, "Error %d in FILE_COMPLETE_SET for Guardian file = \
%s\n", err_elem, filename);
exit(1);
}
/* Get info. about the set of files enabled for common completion */
status = FILE_COMPLETE_GETINFO_(
(short *) info_list, /* array of information elements */
2, /* only two requested */
&num_elem /* actual number of files */
);
if(status) {
fprintf(stderr, "File Complete Getinfo error %d\n", status);
exit(1);
}
/* The program can execute code while the read operations are being
completed by the system. */
for (i = 0; i < 100000; i++) ;
printf("Now issuing FILE_COMPLETE_ to check for I/O completion.\n");
status = FILE_COMPLETE_(
(short *) &comp_info /* completion information */
, /* time limit (* 0.01 sec.) */
, /* array of complete elements */
, /* number of complete elements */
, /* error index */
);
if(status) {
exit(1);
}
User (U or O) Owner
Read Read
Write Write
Execute Execute
Purge (Ignored)
Mappings of OSS file-access permissions to Guardian security are based on user information
and are not predictable based only on file permission information. OSS file-access permissions
do not reflect:
• Safeguard access control lists (ACLs). To determine whether there is an Safeguard ACL on
a Guardian file, use the Guardian FILE_GETINFOLISTBYNAME_ procedure.
• OSS ACLs. To determine whether there is an OSS ACL on an OSS file you can use these
functions:
— The OSS stat(), fstat(), and lstat() system calls return an ACL-PRESENT flag
that specifies if the file or directory has an optional OSS ACL entry.
— Guardian FILE_GETINFOLIST_ and FILE_GETINFOLISTBYNAME_ procedures return
an ACL-PRESENT flag that specifies if the file or directory has a optional OSS ACL
entry.
60 Managing Files
Safeguard Protection and Disk Volumes
You cannot use Safeguard access control lists (ACLs) to protect individual OSS files. However,
you can protect the disk volume in which OSS files reside by restricting the ability of users to
create files in that volume.
If an Safeguard ACL restricts create access within a disk volume where OSS files reside, you
cannot create files in that volume unless you are one of the users listed in the Safeguard ACL. If
you are not listed in the Safeguard ACL, you can still open, read, and write to any existing file
in that volume.
The Safeguard product is a NonStop subsystem. For information about programmatic access to
this subsystem, see the Safeguard Management Programming Manual and the SPI Programming
Manual.
OSS ACLs
OSS ACLs are supported for directories, regular files, first-in, first-out (FIFO) files, and bound
AF_UNIX sockets in Version 3 catalog filesets on systems running J-series RVUs, H06.08 and
later H-series RVUs, and G06.29 and later G-series RVUs.
ACLs offer a greater degree of selectivity than permission bits. ACLs allow a process whose
effective user ID matches the file owner, super ID, or a member of the Safeguard
SECURITY-OSS-ADMINISTRATOR security group to permit or deny access to a file to a list of
specific users and groups.
ACLs are supported as a superset of the UNIX operating system discretionary access control
(DAC) mechanism for files, but not for other objects such as interprocess communication (IPC)
objects.
All OSS system calls that include pathnames are subject to the ACLs on any directory or file in
the path.
For details about OSS ACLs, see “Using OSS Access Control Lists (ACLs)” (page 249).
62 Managing Files
Accessing Files From the OSS API
In the OSS environment, you access OSS files in the same way that you would in any
POSIX-compliant UNIX programming environment. OSS functions are tailored to the OSS
environment and work more efficiently than Guardian procedures on OSS files.
You can access up to four types of Guardian files on physical disk volumes with OSS function
calls:
• Odd-unstructured Format 1 files (file codes 0, 100, and 180). These files permit reading and
writing of both even and odd byte counts and positioning to both even and odd byte
addresses. Unstructured files do not have a built-in record structure.
• EDIT files (file type 101). These files are unstructured. You can access them only for reading.
• Telnet processes.
• For J-series RVUs, H06.06 and later RVUs, and G06.29 and later G-series RVUs,
odd-unstructured Format 2 files (file codes 0, 100, and 180). These files permit reading and
writing of both even and odd byte counts and positioning to both even and odd byte
addresses. Unstructured files do not have a built-in record structure. For detailed information
about accessing these files, see “Accessing OSS Files Larger Than 2 GB” (page 74).
You cannot access:
• Files on logical disk volumes administered through the Storage Management Foundation
(SMF)
• A volume, a subvolume, or a process other than a TTY simulation process (/G/vol,
/G/vol/subvol, or /G/process, respectively)
• A file within a subvolume with a reserved name beginning with ZYQ (for example:
/G/vol2/zyq00004/z000002x)
Odd-unstructured files and EDIT files are opened as OSS regular files.
If you want your application to modify odd-unstructured Guardian files, or if your application
uses data stored in odd-unstructured Guardian files or EDIT files, you can use the interoperability
capabilities of the OSS environment and access these files with OSS functions. If you need to
modify EDIT files or open structured files, you can use Guardian procedures as described in
“Accessing Files From the Guardian API” (page 65).
NOTE: Optical disks are inaccessible directories in /G. This means that OSS functions cannot
open, create, or read files in directories under /G when the files reside on optical disks.
As an alternative to using Guardian procedures when you cannot accomplish a task with OSS
functions, you might be able to accomplish the task with the Guardian C functions. Write a
separately compiled module using Guardian C functions and link (bind) this module into the
OSS program. Whether you should do this depends on whether you can accomplish the required
set of operations with Guardian C functions. Refer to Chapter 1 (page 25) for more information
about calling Guardian C functions from G-series TNS OSS programs.
Example 2-7 (page 64) shows how to read a Guardian file with OSS function calls; in this case,
open() and read(). The Guardian file is accessed through the /G directory.
/* Print the number of bytes read and the first part of the file. */
printf("Number of bytes read = %d\n", nbytes);
buffer[nbytes] = 0; /* make string NULL-terminated */
printf("%s\n", buffer);
return(0);
}
NOTE: If a TNS module calls any of the environment-specific variants, the feature-test macro
_INTEROPERABLE should be specified when the module is compiled. Specifying
_INTEROPERABLE allows subsequent I/O function calls to know which type of I/O stream they
are operating on.
Example 2-8 opens a Guardian file using fopen_guardian() in an OSS module and opens an
OSS file using fopen().
64 Managing Files
Example 2-8 Using fopen_guardian() in an OSS Module
/* Verify current process is an OSS process */
#ifndef _OSS_TARGET
#error “Wrong systype”
#endif
#include <stdio.h>
int main (int argc, char *argv[]) {
FILE *G_File;
FILE *P_File;
int c;
66 Managing Files
Example 2-9 Reading an OSS File in Nowait Mode With Guardian Procedures
/* Reading an OSS file in Nowait Mode with Guardian Procedures */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,READX,AWAITIOX)>
_cc_status CC;
short filenum, bytesread, retcode;
char *pathname;
char buffer[1025]; /* allow for NULL character at end of buffer */
long request_tag;
int i;
Example 2-10 shows the use of the Guardian FILE_OPEN_ and READX procedures to read data
from an OSS file whose name is provided as input to the program. This program waits for I/O
operations to terminate.
68 Managing Files
Example 2-10 Reading an OSS File With Guardian Procedures
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,READX)>
_cc_status CC;
short filenum, bytesread, retcode;
char *pathname;
char buffer[1025]; /* allow for NULL-terminated string */
70 Managing Files
Example 2-11 Using a Guardian Procedure to Get OSS File Information by Name
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(PATHNAME_TO_FILENAME_,FILE_GETINFOBYNAME_)>
char *pathname;
char filename[64];
short filelen;
short status;
short typeinfo[5];
short flags;
Example 2-12 shows the use of the Guardian FILE_OPEN_ and FILE_GETINFO_ procedures to
get information about an OSS file. The file is opened, and the file number is passed to the
FILE_GETINFO_ procedure.
72 Managing Files
Example 2-12 Using a Guardian Procedure to Get OSS File Information by Number
/* Using a Guardian Procedure to Get OSS File info by Number*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(FILE_OPEN_,FILE_GETINFO_)>
short typeinfo[5];
char filename[64];
char *pathname;
NOTE: For J-series RVUs, H06.06 and later H-series RVUs, and G06.29 and later G-series
RVUs, a pax archive file is limited to 8 GB.
• Have an underlying Guardian file format of Format 2. This underlying file format is normally
not visible to customer applications when OSS APIs are used, but might affect program
execution when Guardian APIs are used. For more information, see “Compatibility Issue
For Guardian Files Created by OSS APIs” (page 78)
74 Managing Files
• Can be accessed using 64-bit APIs such as creat64() and open64() only:
— An application can explicitly call the 64-bit version of a function when you use the
#define _LARGEFILE64_SOURCE 1 feature test macro or an equivalent compiler
command option to compile the application.
— An application call to interface() is automatically mapped to the interface64()
function when you use the #define _FILE_OFFSET_BITS 64 feature test macro or
an equivalent compiler command option to compile the application
• Cannot be restored to systems running RVUs that do not support OSS files larger than
approximately 2 GB.
• If OSS APIs are used, large files cannot be accessed from systems running RVUs that do not
support OSS files larger than approximately 2 GB. However, Guardian Enscribe APIs with
64-bit elections can access these files.
Large File Safe (LFS) Applications and Large File Aware (LFA) Appications
An application that is large OSS file safe (LFS) causes no data loss or corruption when it encounters
an OSS file larger than approximately 2 GB. It can not process OSS files larger than approximately
2 GB, but it has the appropriate logic to handle errors or warnings detected during file
manipulation operations and fail gracefully.
An application that is large OSS file aware (LFA) can process OSS files larger than approximately
2 GB with the same functionality as processing OSS files smaller than approximately 2 GB. Such
an application can handle large files as input and generate large files as output. Applications
that are large file aware can also process small files.
76 Managing Files
If a small file is accessed using a 64-bit API:
• The file is automatically converted to use an underlying Guardian file format of Format 2.
• The file no longer has a size limit of approximately 2 GB. It can grow to the size limit for
large files.
The LFA OSS APIs are:
creat64()
open64()
ftruncate64()
lseek64()
fcntl()
fstat64()
lstat64()
stat64()
fstatvfs64()
statvfs64()
readdir64()
ftw64()
nftw64()
glob()
The LFA native C runtime library APIs are:
__ns_backup_fopen64()
__ns_fopen64_special()
fgetpos64()
fopen64()
fopen64_guardian()
fopen64_oss()
fopen64_std_file()
freopen64()
freopen64_guardian()
freopen64_oss()
fseeko64()
fsetpos64()
ftello64()
scandir64()
tmpfile64()
tmpfile64_guardian()
tmpfile64_oss()
The Native C++ runtime libraries do not have new 64-bit specific APIs in the C++ library products.
However, the logic implementing IOStream classes is enhanced to be large OSS file safe for
programs built with the regular compilation environment or large OSS file aware for programs
built with the large file compilation environment (that is, macro _FILE_OFFSET_BITS is defined
to have value 64.).
Interoperability
Opening OSS Files
Applications running on systems that do not include support for OSS large files can use either
OSS or Enscribe APIs to open any OSS file smaller than approximately 2 GB, even if that file is
on a system that includes support for OSS large files.
HP does not support OSS opens of OSS files larger than approximately 2 GB on systems that do
not include support for OSS large files. However, because Enscribe has long understood Guardian
Format 2 files, a program running on a system that does not support large files can use Enscribe
78 Managing Files
However, FILE_OPEN_ fails with error 580 if any of these conditions are true:
• The RVU is earlier than G06.29 or H06.06
• The file code is not 180
• The EOF is greater than the Format 1 limit
Recovery choices include:
• Change the application to accept Guardian Format 2 files.
• Protect the application by converting the file to Guardian Format 1 using the following steps:
>FUP CREATE TEMP, FORMAT 1, TYPE U, ODDUNSTR, CODE 180, &
EXT (28,1400), MAXTENTS 749
Common Completion
Common Completion is an enhancement to the Enscribe file system and the Open System Services
file system that allows completion of a Guardian file or returns ready information for OSS (socket,
OSSTTY, and disk) files for read, write, or exception descriptors. Common Completion is a
combination of an enhanced version of the AWAITIO[X] procedure (for Guardian files) and the
equivalent of the select() function (for OSS files).
For OSS files, select() is used to obtain ready information for OSS socket, OSSTTY, and disk
descriptors. Completion for an OSS file means checking for readiness: that is, either data can be
sent or received, or an exception has occurred.
The select() function checks the status of objects identified by bit masks called file descriptor
sets. Each file descriptor set consists of an array of bits whose relative position and value represent
file descriptors and the status of their corresponding objects. An object is an open file descriptor
for an OSSTTY, a socket, an OSS regular file, a pipe, or a FIFO. There is a file descriptor set for
reading, for writing, and for pending exceptions. OSS and Guardian processes can communicate
within the same processor and between processors and between nodes using FIFOs. However,
they cannot communicate using pipes. Pipes are used to communicate between processes and
their processes
NOTE: Although an OSS socket descriptor is ready, a subsequent I/O operation might not finish
successfully because sockets can be shared by multiple processes. If process A receives notice
that the descriptor is ready for I/O, process B might alter that status before process A can perform
an I/O operation on it.
For Guardian files, AWAITIO[X] is used to complete nowaited Guardian I/O operation.
Completion for Guardian files implies that an I/O operation was initiated in a previous call to a
read or write operation. This I/O operation is completed in AWAITIO[X] and data is returned
to the application.
See the Open System Services System Calls Reference Manual and the Guardian Procedure Calls
Reference Manual for more information.
Common Completion 79
Example 2-13 (page 80) demonstrates the use of select() on FIFOs.
80 Managing Files
fprintf(stderr, "Can't open %s\n", argv[i+1]);
exit(EXIT_FAILURE);
}
sumread = 0;
do {
totread = 0;
for(i = 0; i < nfifo; i++) {
if(nrd[i] < 0) /* don't read if end-of-file */
continue;
if((nrd[i] = read(rd[i], buf[i], 512)) > 0) {
write(fd[i], buf[i], nrd[i]);
totread += nrd[i];
} else
nrd[i] = -1; /* set end-of-file marker */
}
sumread += totread;
} while(totread);
printf("Total bytes read from files = %d\n", sumread);
return(EXIT_SUCCESS); /* write of all fifos done */
}
/* Execute parent program to read the named pipes
using the select() function and non-blocking I/O
*/
printf("Parent process code started.\n");
maxfdp1 = 3; /* Set highest descriptor number */
FD_ZERO(&m_rfds);
for(i = 0; i < nfifo; i++) /* create output files */
if((rd[i] = open(ofile[i], O_WRONLY | O_CREAT, 0644)) < 0) {
fprintf(stderr, "Can't create %s\n", ofile[i]);
exit(EXIT_FAILURE);
}
for(i = 0; i < nfifo; i++) {
if((fd[i] = open(fifo[i], O_RDONLY)) < 0) {
fprintf(stderr, "Can't open fifo %s.\n", fifo[i]);
exit(EXIT_FAILURE);
}
if(fcntl(fd[i], F_SETFL, O_NONBLOCK) < 0) {
fprintf(stderr, "fcntl() error.\n");
exit(EXIT_FAILURE) ;
}
if(fd[i] > maxfdp1)
maxfdp1 = fd[i];
FD_SET(fd[i], &m_frds);
}
maxfdp1++; /* one more than max. file descriptor number */
sumread = 0; /* initialize number of bytes read */
cnt = nfifo; /* number of fifos still open */
while(cnt) {
printf("select starting\n");
s_rfds = m_rfds;
if(select(maxfdp1, &s_rfds, NULL, NULL, NULL) <= 0) {
fprintf(stderr, "select() error %d.\n", errno);
exit(EXIT_FAILURE) ;
}
for(i = 0; i < nfifo; i++) {
nread = 0;
if(FD_ISSET(fd[i], &s_rfds)) {
if((nread = read( fd[i], buf[i], 512)) < 0) {
fprintf(stderr, "read fifo error %d\n", errno);
exit(EXIT_FAILURE);
}
if(nread > 0) { /* some data read */
write(rd[i], buf[i], nread);
sumread += nread;
} else { /* end of file */
FD_CLR(fd[i], &m_rfds ); /* stop reading from this file */
close(fd[i]);
--cnt; /* number of fifos still open */
}
}
} /* end of for loop */
} /* end of while loop */
Common Completion 81
printf("Total bytes read from fifo(s) = %d\n", sumread);
return(EXIT_SUCCESS);
} /* end of main */
Performance Considerations
The following actions improve performance when you use OSS file system functions:
NOTE: Some of these actions affect the configuration of the fileset or of the disk volume and
are not controlled by the application.
• Minimize the number of open operations such as open() and opendir().
• Minimize the use of pipes and FIFOs between processors.
• Minimize the use of AF_UNIX sockets between processes.
• Minimize the use of shared opens (more than one process sharing an open file descriptor)
between processors.
• Minimize the use of operations that alter directory contents, such as creat(), link(),
unlink(), and rename().
• Use file caching, if appropriate (see “File Caching”).
• Use free-space table caching. For more information, see the SCF Reference Manual for the
Storage Subsystem.
• Use O_SYNC when reliability, not performance, is most important.
NOTE: HP recommends that the S_NONSTOP extension not be used in new applications. The
S_NONSTOP extension is ignored on nodes running J-series RVUs or an RVU more recent than
G06.26 or H06.03; the standard O_SYNC feature used with the FTIOMODE attribute provides
better data integrity and improved performance.
• Increase the size of the disk cache, if appropriate. If disk cache is too small, disk processes
might perform unnecessary physical disk I/Os. If disk cache is too large, it can induce
unnecessary memory swap operations and cache faults. (Swaps are also disk I/Os and
therefore time consuming.) Typically, the default values for disk cache is small, so
performance can be slow. There are a number of factors involved in determining the best
disk cache size for your system. For more information, see the SCF Reference Manual for the
Storage Subsystem and the Measure User’s Guide.
File Caching
By default, the OSS environment provides a file cache for regular files in each processor that
does input or output with a disk volume that contains OSS files. HP strongly recommends that
you leave OSS file caching enabled. This cache is necessary for the fault tolerant behavior
controlled by the fileset FTIOMODE or NORMALIOMODE attributes.
If file caching is enabled, the OSS file system determines whether a file should be cached.
If OSS file caching is in effect, the OSS file system reads large blocks of data into its own processor
cache buffer and then resolves user application read requests from that cache buffer. If OSS file
caching is not in effect, the OSS file system does not perform any local caching of data and all
requests are passed to the disk process.
If the OSS file system determines that a file should be cached and all opens of the file are for read
access, then the file is cached on all processors that have opens of the file. The opens must be for
read access only.
The caching state of a file is dynamic and can change as opens, closes, and other events occur on
a file.
82 Managing Files
You should decide whether to use OSS file caching when you first configure a fileset, because
changing the use of OSS file caching requires you to stop the fileset.
Although the storage subsystem can be used to enable or disable file caching for a volume, HP
recommends that you not modify OSS file caching at the disk level. The FTIOMODE and
NORMALIOMODE fileset attributes provide better control over fault-tolerance and performance
for file input or output.
NOTE: HP recommends that the S_NONSTOP extension not be used in new applications. The
S_NONSTOP extension is ignored on nodes running J-series RVUs or an RVU more recent than
G06.26 or H06.03; the standard O_SYNC feature used with the FTIOMODE attribute provides
better data integrity and improved performance.
The attribute settings for NORMALIOMODE are, from highest to lowest fault tolerance and
from lowest to highest performance:
UNBUFFEREDCP
DP2BUFFEREDCP
OSSBUFFEREDCP
DP2BUFFERED (Same as legacy OSS file caching turned off [OSSCACHING OFF])
OSSBUFFERED (Same as legacy OSS file caching turned on [OSSCACHING ON])
If NORMALIOMODE is not specified, the default behavior is OSSBUFFEREDCP.
The FTIOMODE settings are a subset of the NORMALIOMODE settings. The setting used for
the FTIOMODE attribute of a specific fileset must have a fault-tolerance level at least as high as
that of the NORMALIOMODE attribute setting for the fileset. The attribute settings for FTIOMODE
are, from highest to lowest fault tolerance and from lowest to highest performance:
UNBUFFEREDCP
DP2BUFFEREDCP
OSSBUFFEREDCP
If FTIOMODE is not specified, the default behavior is UNBUFFEREDCP.
File caching and buffering affect the data integrity of a file and file transfer speed as described
in Table 2-4.
Table 2-4 I/O Buffering, Fault Tolerance, and Performance
NORMALIOMODE or Behavior Fault Tolerance and Performance
FTIOMODE Attribute Value
UNBUFFEREDCP Uses unbuffered input/output with Provides maximum fault tolerance but
checkpointing. with reduced performance.
DP2BUFFEREDCP Uses disk-process-buffered input/output Provides fault tolerance for single failures,
with checkpointing. with better performance than
DP2 buffers file data and checkpoints the UNBUFFEREDCP.
file state to its backup process to ensure
recovery from single failures.
Performance Considerations 83
Table 2-4 I/O Buffering, Fault Tolerance, and Performance (continued)
NORMALIOMODE or Behavior Fault Tolerance and Performance
FTIOMODE Attribute Value
OSSBUFFEREDCP Uses OSS-buffered input/output with Provides fault tolerance for single failures,
checkpointing. with better performance than
OSS filesystem processes and DP2 share DP2BUFFEREDCP.
responsibility for buffering file data; OSS
provides the buffering whenever possible.
DP2 buffers file data and checkpoints the
file state to its backup process to ensure
recovery from single failures.
OSSBUFFERED Uses OSS-buffered input/output without Provides no fault tolerance, but better
checkpointing. performance than OSSBUFFEREDCP.
84 Managing Files
OSS Function
The name of the function and a brief description.
OSS Notes
Notes about the OSS implementation of the function. The note “Can return extended errors”
means that the function can return errors that are HP extensions to the XPG4 specification.
Refer to the function’s reference page for further information.
Guardian Notes
Notes about using the function when it is called from a Guardian process.
The note “FDM set” (for file, directory, and memory) means that the function is one of a set
of functions that have the following effects when the first of them is called from the Guardian
environment:
• Two Guardian file-system numbers (not necessarily the next two available) are allocated
for the root directory and the current working directory. These file numbers cannot be
closed by calling the Guardian FILE_CLOSE_ procedure.
• The current working directory is assigned from the VOLUME attribute of the Guardian
environment =_DEFAULTS DEFINE.
• The use of static memory by the process increases slightly.
• The functions in the FDM set are access(), chdir(), chmod(), chown(), chroot(),
creat(), creat64()fchmod(), fchown(), fstatvfs(), fstatvfs64(), ftok(),
ftw(), ftw64(), getcwd(), glob(), lchmod(), lchown(), link(), lstat(),
lstat64(), mkdir(), mkfifo(), mknod(), nftw(), nftw64(),open(),
open64(),opendir(), pathconf(), pipe(), readlink(), rename(),
rename_oss(), rmdir(), select(), socket(), socketpair(), stat(),
stat64(), statvfs(),statvfs64(), symlink(), unlink(), and utime().
The information in this table is only a summary of the information in the reference page for a
function. For details, refer to the reference pages either online or in the Open System Services
System Calls Reference Manual and the Open System Services Library Calls Reference Manual.
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 389).
Table 2-5 OSS File-System Functions
OSS Function OSS Notes Guardian Notes
chown() The fchown() function is like the FDM set.Can be used only on files in
fchown() chown()function except that it the /G fileset.
lchown() operates on a file descriptor instead The _POSIX_CHOWN_
Changes the owner and group IDs of of a pathname. RESTRICTEDconstant is ignored for
a file. The lchown() function is similar to files in /G.
the chown() function except when For details on disk file security, refer
the final component of the path to the reference pages.
parameter refers to a symbolic link,
the lchown()function changes access
permissions for the symbolic link
instead of the file to which it refers.
Can return extended errors.
Can return Guardian file-system error
numbers in errno.
86 Managing Files
Table 2-5 OSS File-System Functions (continued)
OSS Function OSS Notes Guardian Notes
confstr()
Determines the current value of a
specified system variable defined by
a string value.
ctermid() If the parameter is a null pointer, the For Guardian processes, it returns a
Generates the pathname for a string is stored in an internal static null pointer and errno is set to
controlling terminal. area and the address is returned. The ENOTOSS.
next call to this function with a null
pointer overwrites the contents of the
internal static area.
Can return extended errors.
fcntl() Does not return EDEADLK. Access to the file through a Guardian
Controls open file descriptors. Advisory record locking is supported procedure call cannot be blocked by
only for regular files; attempts on an OSS lock.
other files give EINVAL. Guardian use of OSS sockets is not
l_len parameter can be negative. supported.
fopen_guardian() Can return Guardian file-system error Distinguishes between text and binary
fopen64_guardian() numbers in errno. files.
Opens a stream (Guardian fopen() fopen64_guardian() can access Explicit calls are made only when the
function). both small files and large files. unique behavior is desired. Otherwise
use fopen().
fsync() Can return extended errors. Time values are not saved for file types
Writes modified data and file Can return Guardian file-system error other than regular files in /G.
attributes to permanent storage. numbers in errno.
88 Managing Files
Table 2-5 OSS File-System Functions (continued)
OSS Function OSS Notes Guardian Notes
ftw() Does not return EINVAL. FDM set.All files in /G that are visible
ftw64() Can return extended errors. to opendir() can be traversed.
Traverses a file tree.
Recursive access from / can cause
unexpected results.
ftw64() can access both small files
and large files.
ioctl() Can return extended errors. A Guardian process cannot receive the
Controls device files. Can return Guardian file-system error SIGWINCH signal.
numbers in errno. The fildes parameter can specify a
terminal file in /G.
lstat() For files other than regular disk files, FDM set.
lstat64() st_size is set to 0 (zero), and for There are security and permission
Provides information about a directories, to 4096. mapping considerations. Refer to the
symbolic link or any file. The following bits are ORed into the reference page for detailed information
st_mode field of the stat structure: about using stat() on Guardian files.
S_IRWXU
S_IRWXG
S_IRWXO
S_IFMT
S_ISVTX
S_NONSTOP
S_ISGID
S_ISUID
Can return extended errors.
lstat64() can access both small
files and large files.
mkdir() Can’t create /lost+found or /dev Succeeds only when creating an empty
Creates a directory. in the root directory of a fileset or subvolume exactly three directories
/dev/tty or /dev/null. under root (/G/vol/subvol).
If there are bits in the mode The resulting directory is owned by
parameter other than permission bits the super ID, and all permission bits
S_ISVTX and S_IFDIR, errno is set are set (rwxrwxrwx).
to EINVAL, or the bits are undefined. The group ID is set to 255.
The group ID of the new directory is
set to the group ID of the parent
directory if S_ISGID is set there,
otherwise, the group ID is set to the
effective group ID of the caller.
Can return extended errors.
90 Managing Files
Table 2-5 OSS File-System Functions (continued)
OSS Function OSS Notes Guardian Notes
rename_guardian() Can return Guardian file-system error Can be used only on Guardian files in
Renames a file in the Guardian file numbers in errno. /G, and the caller must have Guardian
system. write access to the file.
92 Managing Files
Table 2-5 OSS File-System Functions (continued)
OSS Function OSS Notes Guardian Notes
stat() For files other than regular disk files, FDM set.
stat64() st_size is set to 0 (zero), and for There are security and permission
Provides information about a directories, to 4096. mapping considerations. Refer to the
file.stat() function. The following bits are ORed into the reference page for detailed information
st_mode field of the stat structure: about using stat() on Guardian files.
S_IRWXU
S_IRWXG
S_IRWXO
S_IFMT
S_ISVTX
S_NONSTOP
S_ISGID
S_ISUID
Can return extended errors.
Can return Guardian file-system error
numbers in errno.
stat64() can access both small files
and large files.
umask()
Sets and gets the value of the file
mode creation mask.
writev() Can return Guardian file-system error Attempting to write to a Guardian file
Writes to a file from scattered buffers. numbers in errno. that is locked with Guardian locks
returns -1 and sets errno to
EGUARDIANLOCKED.
AWAITIO[X]
Checks for completion of read operations pending on the
$RECEIVE file.
FILE_ALTERLIST_ Fails with file-system error 1163 when the file is an OSS
Changes certain attributes of a Guardian disk file that are file.
normally set when the file is created.
FILE_COMPLETE_GETINFO_
Provides information about the set of files that are enabled
for completion by FILE_COMPLETE_.
94 Managing Files
Table 2-6 Guardian File-System Procedures (continued)
Guardian Procedure OSS Notes
FILE_CREATE_ Fails with file-system error 1163 when the file is an OSS
Creates a Guardian disk file specifying commonly used file.
disk file properties.
FILE_CREATELIST_ Fails with file-system error 1163 when the file is an OSS
Creates a Guardian disk file specifying properties in file.
addition to commonly used disk file properties.
FILE_PURGE_ Fails with file-system error 1163 when the file is an OSS
Deletes a disk file that is not open. file.
FILE_RENAME_ Fails with file-system error 564 when the file is an OSS
Changes the name of an open disk file. file.
LOCKFILE Fails with file-system error 2 when the file is an OSS file.
Excludes other users from access to a Guardian file.
LOCKREC Fails with file-system error 2 when the file is an OSS file.
Excludes other users from access to a record.
READLOCK[X] Fails with file-system error 2 when the file is an OSS file.
Sequentially locks and reads records in a Guardian disk
file, just like combinations of LOCKREC and READ[X].
READUPDATELOCK[X] Fails with file-system error 2 when the file is an OSS file.
Performs random processing of records in a Guardian
disk file.
SETMODE Fails with file-system error 2 when the file is an OSS file.
Sets device-dependent functions.
WRITEUPDATEUNLOCK[X] Fails with file-system error 2 when the file is an OSS file.
Alters, then unlocks the contents of a Guardian record at
the current position.
96 Managing Files
3 Managing Processes
You can create, control, and terminate OSS processes as you would in a standard UNIX
environment. In addition to the standard set of UNIX process-management functions, there are
several HP extension functions that provide flexibility in propagating attributes during process
creation.
OSS processes have a full set of Guardian attributes as well as OSS-specific attributes. Most
Guardian process-management procedures can access OSS processes, and some OSS
process-management functions can access Guardian processes.
This section discusses the following topics:
Topic Content
“Common and Unique Characteristics” (page 97) Summary of the differences between UNIX and OSS
process management.
“Process Attributes” (page 105) Which OSS attributes Guardian processes have, examples
of Guardian attributes that are important to OSS
processes, and a table comparing attributes in OSS and
Guardian processes.
“Process-Management Interoperability” (page 107) Capability of OSS functions to manage Guardian processes
and of Guardian procedures to manage OSS processes.
“Creating and Controlling Processes” (page 111) OSS functions and Guardian procedures to create,
suspend, activate, and terminate processes.
“Querying the Process Environment” (page 121) OSS functions and Guardian procedures to get
information about both OSS and Guardian processes and
their environments.
“Modifying the Process Environment” (page 127) OSS functions and Guardian procedures to modify
characteristics about both OSS and Guardian processes
and their environments.
“OSS Process-Management Functions” (page 141) List of each OSS process-management function with notes
about its OSS implementation and use on Guardian
processes.
“Guardian Process-Management Procedures” (page 146) List of each Guardian process-management procedure
with notes about its use on OSS processes.
NOTE: These examples use the AF_INET sockets functions, which provide an interface to HP
NonStop TCP/IP. The programs could also be written using the AF_INET6 sockets functions to
interface to HP NonStop TCP/IPv6. For information and examples of AF_INET6 sockets usage,
refer to the TCP/IP Programming Manual.
In this application, dlaunch1 creates an AF_INET socket and listens for incoming connections
from one or more copies of requester2. Upon receipt of a connection, dlaunch1 uses fork()
to create a duplicate of itself as a child process.
The child process duplicates itself again with another call to fork() to create a grandchild. The
grandchild overwrites itself by starting server, using an execv() call. The child process exits
immediately so that the dlaunch1 call to the wait() function prevents the child process from
becoming a zombie process and wasting processor resources.
98 Managing Processes
Example 3-1 Dynamic Launcher Program
/* dlaunch1.c
*
* Simple OSS example using OSS socket APIs for communication
* between requester and server.
*
* dlaunch1 (dynamic launcher 1) is an inetd-like program which
* accepts socket connections and exec's a dserver process for
* each connection.
*
* dserver reads stdin and echoes to stdout. dlaunch1 and dserver
* write progress messages and error messages to stderr.
*
* dlaunch1 and the multiple dserver processes run on the same cpu.
*/
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, PROCESSHANDLE_DECOMPOSE_)>
/* Get server port from the command line or use default 12345 */
if (argc > 1)
/* fd usage
* 0 stdin - not used by dlaunch1, set up for dserver
* 1 stdout - not used by dlaunch1, set up for dserver
* 2 stderr - used by dlaunch1 for messages, inherited by dserver
* 3 listenfd - used by dlaunch1 for connections,
* not inherited by dserver
*/
close(STDIN_FILENO);
close(STDOUT_FILENO);
listenfd = fd;
fcntl(listenfd, F_SETFD, FD_CLOEXEC); /* don't propagate fd to children */
FD_ZERO(&fdset);
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, PROCESSHANDLE_DECOMPOSE_)>
FD_ZERO(&fdset);
/* echo on stdout */
if (write(STDOUT_FILENO, msg_buff, bytesread) < 0)
{
fprintf(stderr, "dserver [cpu %d] - "
"write(fd %d) failed [errno %d]\n",
cpu, STDOUT_FILENO, errno);
exit(1);
}
}
} /* end while (1) */
}
errno = 0;
cval = getpriority(which, who);
if(errno) {
fprintf(stderr, "getpriority error, args = %d, %d\n", which, who);
exit(1);
}
return(cval);
}
/*
Read the value of the process priority increment from the command line.
If the value is not provided, print usage message and exit.
If the value is invalid, print error message and exit.
*/
if(argc > 1) {
prval = atoi(argv[1]);
if(abs(prval) > (2*NZERO-1)) {
fprintf(stderr, "Invalid priority increment %s\n", argv[1]);
exit(1);
}
} else {
fprintf(stderr, "Usage: nicegetp value [0 to 150]\n");
exit(1);
}
Process Attributes
All processes, OSS and Guardian, have Guardian attributes and some OSS attributes. OSS
processes are basically Guardian processes with some additional OSS-specific attributes, such
as OSS process ID.
Ancestors
Groups
Identification
Program type
Terminals
Process-Management Interoperability
In general, you should manage OSS processes with OSS functions, because your applications
are more portable. However, there might be cases in which you want to use Guardian procedures
to manage OSS processes or OSS functions to manage Guardian processes. For example, if you
want to use a product or subsystem that runs only in the Guardian environment, you might need
to manage a process from the opposite environment.
The process handle of an OSS process allows most Guardian process-management procedures
to access it. On the other hand, a Guardian process does not have an OSS process ID, which is
required by many OSS process-management functions. This means that some OSS
process-management functions cannot access Guardian processes.
Table 3-2 lists and provides a short description of the Guardian process-management procedures
that can access OSS processes. Note that the only principal Guardian process-management
procedure missing from this list is PROCESS_LAUNCH_, because it can create only Guardian
processes. Table 3-5 (page 147) provides a summary of all Guardian process-management
procedures.
Procedures that are indicated as “superseded” in the Guardian Procedure Calls Reference Manual
are not included in this table, because you should not use them for new program development.
Table 3-2 Guardian Process-Management Procedures That Can Access OSS Processes
Guardian Procedure Description
PROCESSHANDLE_COMPARE_ Compares two process handles and reports whether they are identical,
represent different processes of the same process pair, or are different
PROCESSHANDLE_TO_STRING_ Converts a process handle to a process string, which can identify a process
or set of processes
PROCESSNAME_CREATE_ Returns a unique process name that is suitable for passing to the
PROCESS_CREATE_ procedure
PROCESSSTRING_SCAN_ Scans an input string for a process string and returns the corresponding
process handle or a single component of the process string converted to
internal form
SIGACTION_INIT_2 Establishes the initial state of signal handling for the calling process
3
SIGACTION_RESTORE_ Restores the signal-handling state stored by a call to
SIGACTION_SUPPLANT_
SIGACTION_SUPPLANT_4 Saves the current signal-handling state and allows a subsystem to take
over signal handling temporarily
Table 3-3 lists and provides a short description of the OSS process-management functions that
can access Guardian processes. Table 3-4 (page 141) provides a summary of all OSS
process-management functions.
NOTE: To determine which RVUs support an OSS function, see Appendix A: Documented
OSS Functions (page 389).
Table 3-3 OSS Process-Management Functions That Can Access Guardian Processes
OSS Function Description
alarm() Sets or changes a timer that expires at a specified time in the future
getsid() Gets the group ID of the process that is the session leader of the specified process
setpgrp() Creates a new session when the calling process is not a process group leader, and sets
the process group ID of the calling process
setregid() Sets the real and effective group IDs of the current process
setreuid() Sets the real and effective user IDs of the current process
sigpending() Returns the set of signals that are blocked from delivery and pending to the calling
process
sigsetjmp() Saves the current execution context and can save the current process signal mask
sigsuspend() Changes a process signal mask and suspends the calling process
uname() Gets information identifying the system on which the calling process runs
NOTE: You can use OSS signals functions with Guardian native processes; you cannot use
them with Guardian TNS processes.
int main(void)
{
char buf[4096];
pid_t pid;
int status, cnt;
char *ptr;
/* Get parameters for the child process from the command line. */
printf("%% "); /* print prompt (printf requires %% to print %) */
while (fgets(buf, 4096, stdin) != NULL) {
ptr = buf;
buf[strlen(buf) - 1] = '\0'; /* replace newline with NULL */
Note 1
The tdmext.h library header file defines the input structure containing Guardian process
attributes to be assigned to the new process. It also defines the output structure containing
optional process identification and error information.
Note 2
To set attributes in the new process, you must declare the procext (input) and procresults
(output) structures and initialize them with default values. Then you can set attributes using
literals defined in tdmext.h.
Note 3
To set the process name, request a system-generated process name before calling tdm_fork()
and pass your process name to tdm_evecvep(). If you attempt to pass your name to
tdm_fork() and use the same name in the call to tdm_execvep(), you get an error stating
that the process already has a name.
Note 4
After the call to tdm_fork(), the child process has its own unique OSS process ID, which
does not change. It also has a process handle that does change after the call to
tdm_execvep().
Example 3-5 creates a named process with a system-generated name using tdm_spawnp(). By
setting fields in the inherit structure, the child process becomes a member of a group other than
the parent’s process group, and the child process is the leader of the new process group.
int main(void)
{
char buf[4096];
pid_t pid;
int status, cnt;
int fd_count, fd_map[20];
char *ptr;
/* Get parameters for the child process from the command line. */
printf("%% "); /* print prompt (printf requires %% to print %) */
while (fgets(buf, 4096, stdin) != NULL) {
ptr = buf;
buf[strlen(buf) - 1] = '\0'; /* replace newline with NULL */
Note 1
The spawn.h library header file defines the inherit structure, which allows you to specify
the process group ID and signal mask of the new process and a list of signals that the child
process will take default action on.
Note 2
The fd_count and fd_map parameters allow you to control the file descriptors the child
process inherits from the parent. fd_count specifies the number of file descriptors designated
by fd_map. fd_map specifies how the file descriptors in the parent process map to the file
descriptors in the child process. That is, the file descriptor specified in fd_map [0] is copied
to file descriptor 0 (zero) in the child process, and so on.
char *pname;
short errordetail;
short outlen;
char *proc_name;
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include <spawn.h>
#include <tdmext.h>
#include <zsysc>
#include <cextdecs.h(FILE_OPEN_, FILE_GETINFO_, READX, MONITORCPUS,\
PROCESS_SPAWN_, PROCESS_GETINFOLIST_, FILENAME_TO_PATHNAME_)>
/*
* This procedure converts an internal file descriptor to an OSS pathname.
*/
/*
* This procedure returns nonzero if the specified OSS PID identifies
* an existing process. Process handle is retrieved as a test.
*/
int valid_pid(pid_t pid)
{
short err;
short err_detail;
short len;
short phandle[10];
short ret_attr = 48; /* get process handle */
err = PROCESS_GETINFOLIST_(/*cpu*/,/*pin*/,/*node*/,/*nodelen*/,/*phandle*/,
&ret_attr, 1, phandle, (short)sizeof(phandle), &len,
&err_detail, 3 /* get info for PID specified */ ,
/*srchattr*/, /*srchattrcnt*/,
/*srchval*/, /*srchvalcnt*/, pid);
return ( err == 0 );
}
short processhandle[10];
short mom_processhandle[10];
short gmom_processhandle[10];
short fnlen, priority, htlen, caid, paid, jobid, proglen, swaplen;
short errordetail;
long long proc_time;
char proc_fname[64];
char hometerm[64];
char programfile[64];
char swapfile[64];
short proctype;
long osspid;
/* Get the process name from the command line. If not supplied, use the
current process. Use the process name to get the process handle. */
if(argc > 1) {
retcode = FILENAME_TO_PROCESSHANDLE_(
argv[1], /* process filename */
(short) strlen(argv[1]), /* length of process filename */
processhandle /* process handle */
);
if(retcode != 0) {
fprintf(stderr, "Invalid process name %s\n", argv[1]);
exit(1);
}
} else {
printf("Using current process\n");
retcode = PROCESSHANDLE_GETMINE_(processhandle);
if (retcode != 0) {
fprintf(stderr, "Can't get current process handle\n");
exit(1);
}
}
short processhandle[10];
short attr_list[] = { /* list of attributes for which values are
to be returned */
21, /* real group ID */
22, /* real user ID */
80, /* effective group ID */
23, /* effective user ID */
90, /* OSS process ID */
94, /* OSS parent process ID */
26, /* OSS session leader ID */
98, /* OSS group leader PID */
27, /* OSS controlling terminal */
111, /* current size of native heap area */
112, /* maximum size of native heap area */
31, /* wait state */
32, /* process state */
48 /* process handle */
};
short attr_count; /* number of attributes */
short values_list[8000]; /* buffer of return values */
short values_len; /* size of return values information*/
short errordetail; /* additional error information */
short srch_option; /* search option */
short srch_attr_list[] = { 28 }; /* attribute code specifying search
criteria. 28 is process type (OSS
or Guardian). */
short srch_attr_count; /* number of search criteria */
short srch_values_list[1024]; /* buffer of return values */
short srch_values_len; /* size of return values */
char ctty[100]; /* controlling terminal */
pid_t osspid; /* OSS process ID */
/* Get information for the process specified by the OSS process ID. */
if(argc > 1) {
osspid = atoi(argv[1]);
} else
osspid = getpid();
attr_count = (short)(sizeof(attr_list)/sizeof(short));
srch_option = 3; /* return info for process whose
OSS process ID is specified */
retcode = PROCESS_GETINFOLIST_(
, /* processor */
, /* process ident number (PIN) */
, /* node name */
, /* length of node name */
, /* process handle */
attr_list, /* attribute list to be returned */
attr_count, /* number of attributes */
values_list, /* list of output values */
1024, /* maximum number of values */
&values_len, /* length of list returned */
&errordetail, /* details of any errors */
Example 3-11 Setting the User ID of the Current Process Using setuid()
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
uid_t uid;
struct passwd *pp;
int retcode;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(PROCESS_SETINFO_,PROCESS_SETSTRINGINFO_)>
Performance Considerations
You can improve the performance of your applications with respect to process management by
following these recommendations:
• Minimize the use of the process-creation functions. There is a lot of system overhead involved
in creating processes, so use static server and demon processes whenever possible. Create
a process and do not terminate it until the program no longer needs it.
• Distribute the workload across processors. Specify the processor using the HP extension
functions when creating a process.
• Create processes in one step instead of two. Use the tdm_spawn() or tdm_spawnp()
function instead of calling the fork() or tdm_fork() function followed by one of the
exec or tdm_exec set of functions.
The following subsections illustrate these performance considerations and actions:
• “Using Dynamic Servers Spread Across Available Processors” (page 130)
• “Using Static Servers Spread Across Available Processors” (page 134)
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <netinet/in.h>
#include <tdmext.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, \
PROCESSHANDLE_DECOMPOSE_, \
PROCESSORSTATUS)>
/* Get server port from the command line or use default 12345 */
if (argc > 1)
addr.sin_port = (short)atoi(argv[1]); /* use command line arg */
else
addr.sin_port = 12345; /* use default */
/* fd usage
* 0 stdin - not used by dlaunch2, set up for dserver
* 1 stdout - not used by dlaunch2, set up for dserver
* 2 stderr - used by dlaunch2 for messages,
* inherited by dserver
* 3 listenfd - used by dlaunch2 for connections,
* not inherited by dserver
*/
close(STDIN_FILENO);
close(STDOUT_FILENO);
listenfd = fd;
fcntl(listenfd, F_SETFD, FD_CLOEXEC); /* don't propagate fd to children */
FD_ZERO(&fdset);
peparm.pe_cpu = cpuindex;
inherit.flags = 0;
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <tdmext.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, \
PROCESSHANDLE_DECOMPOSE_, \
PROCESSORSTATUS)>
/* Get server port from the command line or use default 12345 */
if (argc > 1)
addr.sin_port = (short)atoi(argv[1]); /* use command line arg */
else
addr.sin_port = 12345; /* use default */
listenfd = fd;
fcntl(listenfd, F_SETFD, FD_CLOEXEC); /* don't propagate fd on spawn */
FD_ZERO(&fdset);
/* fd usage
* 2 stderr - used by slaunch1 for messages,
* inherited by sserver
* 3 listenfd - used by slaunch1 for connections, not inherited by sserver
* y fd - accepted connection, passed to sserver and closed
* x serverfd[cpu] - slaunch1 fd corresponding to sserver stdin
*/
inherit.flags = 0;
peparm.pe_cpu = cpuindex;
close(STDIN_FILENO);
close(STDOUT_FILENO);
cpuindex = 0;
fdmsghdr.msg_iov = iov;
fdmsghdr.msg_iovlen = 1;
iov[0].iov_base = &cpuindex; /* sent but not used */
iov[0].iov_len = sizeof(cpuindex);
fdmsghdr.msg_control = &fdadata;
fdmsghdr.msg_controllen = sizeof(fdadata);
fdadata.fdcmsghdr.cmsg_len = sizeof(fdadata);
fdadata.fdcmsghdr.cmsg_level = SOL_SOCKET;
fdadata.fdcmsghdr.cmsg_type = SCM_RIGHTS;
fdadata.fd = -1; /* set prior to each
* sendmsg() call */
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <tdmext.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, \
PROCESSHANDLE_DECOMPOSE_, PROCESSORSTATUS)>
fdcount = 1;
highfd = STDIN_FILENO;
fdpassfd = STDIN_FILENO;
FD_ZERO(&fdset);
FD_SET(fdpassfd, &fdset); /* initially fdset has only one active fd */
fdmsghdr.msg_iov = iov;
fdmsghdr.msg_control = &fdadata;
fdmsghdr.msg_controllen = sizeof(fdadata);
fdadata.fdcmsghdr.cmsg_len = sizeof(fdadata);
fdadata.fdcmsghdr.cmsg_level = SOL_SOCKET;
fdadata.fdcmsghdr.cmsg_type = SCM_RIGHTS;
fdadata.fd = -1; /* set by each recvmsg() call */
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 389).
Table 3-4 OSS Process-Management Functions
OSS Function OSS Notes Guardian Notes
execl() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
pathname, a set of environment Guardian function or procedure.
strings, and **environ.
execle() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
pathname, a set of environment Guardian function or procedure.
strings, and an undeclared envp
array.
execlp() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
filename, a set of environment strings, Guardian function or procedure.
and **environ.
execv() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
pathname, an argv array, and Guardian function or procedure.
**environ.
execve() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
pathname, an argv array, and an Guardian function or procedure.
undeclared envp array.
execvep() Can return extended errors. Sets errno to the ENOTOSS value
Replaces the current process image Propagates open file descriptors when called from a Guardian process.
with a new process image, using a except those opened using a
filename, an argv array, and Guardian function or procedure.
**environ.
fork() Can return extended errors. Sets errno to the ENOTOSS value
Creates an OSS process. The child process shares directory when called from a Guardian process.
streams with the parent. They share
the same block of directory entries,
but each stream can be used by only
one of the processes.
Propagates open file descriptors
except those opened using a
Guardian function or procedure.
getenv()
Returns the value of an environment
variable.
geteuid()
Gets the effective user ID of the
calling process.
getppid() If the parent process terminates or the Sets Guardian trap number 5 when
Gets the OSS parent process ID of the calling process was created by a called from a Guardian process.
calling process. Guardian process, it returns a parent
process ID of 1.
getsid() Can return extended errors. Sets errno to the ENOTOSS value and
Gets the group ID of the process that sets Guardian trap number 5 when
is the session leader of the specified called from a Guardian process.
process
longjmp()
Performs a nonlocal goto.
nftw() Can return extended Guardian files that are visible to the
nftw64() errors.nftw64() can access both opendir() function can be traversed.
Traverses a file tree. small files and large files. Security controls on Guardian objects
do not affect the outcome of a call to
nftw().
Two Guardian file system file numbers
(not necessarily the next two available)
are allocated for the root directory and
the current working directory.
The current working directory is
assigned from the VOLUME attribute
of the Guardian environment
=_DEFAULTS DEFINE.
The use of static memory by the
process increases slightly.
pause() Can return extended errors. Sets errno to the ENOTOSS value
Suspends the calling process until a when called from a Guardian TNS
signal is received. process.
putenv()
Sets an environment variable.
raise() Can return extended errors. Sets errno to the ENOTOSS value
Sends a signal to the calling process. when called from a Guardian TNS
process.
setgid()
Sets the group ID of the calling
process.
setjmp()
Saves the current execution context.
setpgid() Can return extended errors. Sets errno to the ENOTOSS value and
Sets the process group ID of the sets Guardian trap number 5 when
calling process. called from a Guardian process.
setpgrp() Can return extended errors. Sets errno to the ENOTOSS value and
Creates a new session when the sets Guardian trap number 5 when
calling process is not a process group called from a Guardian process.
leader, and sets the process group ID
of the calling process.
setregid()
Sets the real and effective group IDs
of the current process
setreuid()
Sets the real and effective user IDs of
the current process
setsid() Can return extended errors. Sets errno to the ENOTOSS value and
Creates a new session and sets the sets Guardian trap number 5 when
process group ID. called from a Guardian process.
sigaction() Can return extended errors. Sets errno to the ENOTOSS value
Specifies the action to be taken upon HP has defined several new signals. when called from a Guardian TNS
delivery of a signal. process.
sigaddset() Can return extended errors. Not meaningful when called from a
Adds a signal to a signal set. Guardian TNS process.
sigdelset() Can return extended errors. Not meaningful when called from a
Deletes a signal from a signal set. Guardian TNS process.
sigemptyset() Can return extended errors. Not meaningful when called from a
Initializes a signal set to exclude all Guardian TNS process.
signals.
sigfillset() Can return extended errors. Not meaningful when called from a
Initializes a signal set to include all Guardian TNS process.
signals.
sigismember() Can return extended errors. Not meaningful when called from a
Tests whether a signal is a member Guardian TNS process.
of a signal set.
signal() Can return extended errors. Sets errno to the ENOTOSS value
Specifies the action to be taken upon HP has defined several new signals. when called from a Guardian TNS
delivery of a signal. process.
sigpending() Can return extended errors. Sets errno to the ENOTOSS value
Returns the set of signals that are when called from a Guardian TNS
blocked from delivery and pending process.
to the calling process.
sigprocmask() Can return extended errors. Sets errno to the ENOTOSS value
Changes or examines a process signal HP has defined several new signals. when called from a Guardian TNS
mask. process.
sigsuspend() Can return extended errors. Sets errno to the ENOTOSS value
Changes a process signal mask and HP has defined several new signals. when called from a Guardian TNS
suspends the calling process. process.
tdm_spawn() Can return extended errors. Sets errno to the ENOTOSS value
tdm_spawnp() Is an extension to the XPG4 when called from a Guardian process.
Creates a new OSS process with a specification.
specified executable image (with HP
extensions). Produces a new OSS process by
combining the function of
tdm_execve() or tdm_execvep()
with tdm_fork(), but with the
following additions:
• Parameters control the file
descriptors the child process
inherits from the parent process.
• The inherit structure allows the
process group ID and signal mask
of the child process to be specified
in addition to a list of signals that
the child process takes default
action on.
• Does not propagate file locks.
times() Can return extended errors. Does not maintain child times.
Gets calling process and child process There is no overflow limit for the Accumulates all processor time as user
times. fields in the tms structure. time.
Might not maintain elapsed time
correctly if the processor’s internal
clock is reset.
wait() If a parent process terminates without Sets errno to the ENOTOSS value
waitpid() waiting for all of its child processes when called from a Guardian process.
Wait for a child process to terminate. to terminate, the remaining child
processes are assigned a parent
process ID of 1.
CHILD_LOST_ An OSS parent process must read its $RECEIVE file for
Examines a system message to determine whether a system messages.
process has stopped. If an OSS process is reading Guardian system messages
to monitor an OSS process, it might appear that the
monitored process is alive when it has stopped. See
“Monitoring OSS Processes Reading Guardian System
Messages” (page 117).
FILENAME_TO_PROCESSHANDLE_
Converts a Guardian (process) filename to a process
handle.
OSS_PID_NULL_
Returns a null OSS process ID.
PROCESS_ACTIVATE_ Has the same effect as calling the OSS kill() function
Returns a suspended process to a ready state. with SIGCONT as the value of the signal parameter.
PROCESS_GETINFO_
Gets a limited set of information about a process.
PROCESS_GETINFOLIST_
Gets detailed information about a process or set of
processes.
PROCESS_SETSTRINGINFO_
Modifies a single string-form attribute of a process.
PROCESS_SUSPEND_ Has the same effect as calling the OSS kill() function
Places a process into a suspended state. with SIGSTOP as the value of the signal parameter.
PROCESSHANDLE_DECOMPOSE_
Returns one or more parts of a process handle.
PROCESSHANDLE_GETMINE_
Gets the process handle of the calling process.
PROCESSHANDLE_NULLIT_
Initializes a process handle to a null value.
PROCESSHANDLE_TO_CRTPID_
Converts a process handle to the corresponding Guardian
process ID (CRTPID).
PROCESSHANDLE_TO_FILENAME_
Converts a process handle to a Guardian (process)
filename.
PROCESSHANDLE_TO_STRING_
Converts a process handle to a process string, which can
identify a process or set of processes.
PROCESSNAME_CREATE_
Returns a unique process name that is suitable for passing
to the PROCESS_CREATE_ or PROCESS_SPAWN_
procedures.
PROCESSSTRING_SCAN_
Scans an input string for a process string and returns the
corresponding process handle or a single component of
the process string converted to internal form.
SIGACTION_INIT_
Establishes the initial state of signal handling for the
calling process.
SIGACTION_RESTORE_
Restores the signal-handling state stored by a call to
SIGACTION_SUPPLANT_.
SIGACTION_SUPPLANT_
Saves the current signal-handling state and allows a
subsystem to take over signal handling temporarily.
SIGJMP_MASKSET_
Saves the process signal mask in a jump buffer.
NOTE: You need to read this section if (and only if) your G-series OSS TNS programs use
Guardian procedures to share memory with other TNS processes. This section does not apply
to system running H-series RVUs because the H-series OSS environment does not support TNS
programs.
OSS processes can use OSS functions and Guardian procedures to share memory with other OSS
processes. To share memory with Guardian processes, OSS processes must use Guardian
procedures.
OSS functions allow (OSS) processes to share flat extended data segments. Guardian procedures
allow processes to share both flat and selectable extended data segments.
This section describes the differences between flat and selectable extended data segments and
why OSS TNS processes should not attempt to share selectable segments with other processes.
This section discusses the following topics:
Topic Content
“The Operating Environment for NonStop Systems” Summary of the differences between UNIX and OSS
(page 26) memory management.
“Memory-Management Interoperability” (page 150) Capability of OSS and Guardian processes to manage
memory using OSS and Guardian memorymanagement
mechanisms.
“About Extended Data Segments” (page 150) Overview of flat and selectable extended data (memory)
segments.
“When Processes Share Memory Using Guardian Recommendations and cautions about sharing flat and
Procedures” (page 151) selectable segments between TNS processes.
“Performance Considerations” (page 152) Suggestions regarding the use of Guardian memory
management mechanisms to improve application
performance.
“OSS Memory-Management Functions” (page 152) List of each OSS memory-management functions with
notes about its use when called from a Guardian
procedure.
“Guardian Memory-Management Procedures” (page 152) List of each Guardian memory-management procedure
with notes about its use when called from an OSS process.
Memory-Management Interoperability
OSS processes share and synchronize access to flat segments using OSS shared-memory and
semaphore functions or using Guardian procedures. OSS TNS processes cannot share selectable
segments using Guardian procedures.
Guardian processes share and synchronize access to memory using Guardian shared-memory
and semaphore procedures. Guardian processes cannot use OSS functions to share and
synchronize access to memory.
If Guardian and OSS processes want to share and synchronize access to memory, they must use
Guardian shared-memory and semaphore procedures.
Selectable Segments
Selectable segments all share the same address space; all selectable segments have the same
starting address. Thus, only one selectable segment is available to a process at any given time.
You select a segment, or make a segment current, with the SEGMENT_USE_ procedure.
For a discussion of using extended segments in application programs, see the Guardian
Programmer’s Guide. For information about memory layout on NonStop systems, see the
appropriate server description manual.
NOTE: To determine which RVUs support an OSS function, see Appendix A: Documented
OSS Functions (page 389).
Table 4-1 OSS Memory Management Functions
OSS Function Guardian Notes
bcopy()
Copies an area of memory.
bzero()
Zeroes an area of memory.
heap_check()
Checks the consistency of the runtime heap.
heap_check_always()
Controls whether the run-time heap consistency is
checked automatically.
heap_min_block_size()
Specifies the minimum block size to attempt to use when
allocating from the heap.
ADDRESS_DELIMIT_
Returns information about a particular area of the user's
logical address space, including the addresses of the first
and last bytes in that area.
MOVEX
Transfers data from one extended data (memory) segment
to another.
POOL_CHECK_
Returns memory pool error information.
POOL_DEFINE_
Defines the bounds of a memory pool in an extended data
(memory) segment or in the user data segment.
POOL_GETINFO_
Returns information about a memory pool.
POOL_GETSPACE_
Obtains a block of storage from a memory pool.
POOL_PUTSPACE_
Returns a block of storage to a memory pool.
POOL_RESIZE_
Changes the size of an existing memory pool.
RESIZESEGMENT
Changes the size of an existing extended data (memory)
segment.
SEGMENT_GETINFO_
Returns information about an extended data segment.
SEGMENT_USE_
Makes a selectable segment current (a flat segment need
not be made current). It also returns the last selectable
segment in use.
SETMODE
Can be used to speed large transfers of data between an
extended data (memory) segment and a file (option 141).
Topic Content
“Common and Unique Characteristics” (page 155) Summary of the differences between OSS and UNIX time
management.
“Process Attributes” (page 105) The objects on which you can use time-management
functions and procedures.
“Querying the System Clock” (page 156) How to obtain and format the system date and time.
“Limiting Processor Time Use” (page 157) How to use the SETLOOPTIMER procedure in an OSS
program.
“OSS Time-Management Functions” (page 157) List of each OSS time-management function with notes
about the OSS implementation and its use on Guardian
objects.
“Guardian Time-Management Procedures” (page 160) List of each Guardian time-management procedure with
notes about its use on OSS objects.
Function Summary
mktime() Converts a broken-down time into time since the Epoch (00:00:00 UTC January
1, 1970 A.D.).
Time-Management Interoperability
You can use Guardian time-management procedures from the OSS environment.
Guardian system clock procedures and OSS system clock functions can be called from both
Guardian and OSS processes. Because the OSS and Guardian time formats are incompatible,
only Guardian system clock procedures work on Guardian time formats and only OSS system
clock functions work on OSS time formats.
You can use the MYPROCESSTIME, PROCESS_GETINFO_, and PROCESS_GETINFOLIST_
procedures and the Measure product to obtain time information about an OSS process. The
PROCESS_GETINFO_ and PROCESS_GETINFOLIST_ procedures are especially useful in that
they can obtain information not just about the calling process, but about another process that
you specify.
When a Guardian process calls the OSS times() function, only restricted information is returned:
times are available for Guardian processes but not for processes that act on behalf of a Guardian
process.
You can use the utime() function to change Guardian file access and modification times of
unstructured files.
The alarm() and ualarm() functions use OSS signals to notify OSS processes and do not work
with Guardian processes, because OSS signals cannot be sent to Guardian processes.
You can use the Guardian SETLOOPTIMER procedure to limit processor time use in OSS
processes.
Beginning of Time 00:00:00 UTC January 1, 00:00 December 31, 1974 12:00 (noon) UTC January
1970 A.D. (the Epoch) A.D. 1, 4713 B.C.
Guardian system clock procedures work only on Guardian timestamp formats, and OSS system
time-management functions work only on OSS timestamp formats. For example, the
alarm() A SIGLIMIT signal is delivered to Does not work with Guardian TNS
Sets or changes the time-out value for the process if the function call fails. processes because OSS signals cannot
an interval timer. be sent to a Guardian TNS process.
asctime()
Converts a date and time to a string.
Refer to ctime().
clock()
Reports processor time used.
ctime()
Converts time units.
difftime()
Computes the difference between two
calendar time values. Refer to
ctime().
getdate() Can be called only by native Can be called only by native processes.
Converts user format date and time. processes.
gmtime()
Converts a time value to
broken-down Coordinated Universal
Time (UTC) time. Refer to ctime().
localtime()
Converts a time value to
broken-down local time. Refer to
ctime().
mktime()
Converts a broken-down time into
time since the Epoch (00:00:00 UTC
January 1, 1970 A.D.). Refer to
ctime().
strftime()
Converts a date and time to a string.
strptime()
Converts a character string to a time
value.
time()
Obtains the time in seconds since the
Epoch (00:00:00 UTC January 1, 1970
A.D.).
times() Time values are approximate. When called from a Guardian process,
Obtains process and child process Times are not calculated for a process the following restrictions apply:
elapsed times. if it costs more to compute the • Child times are not maintained.
running time than to run the process • All processor time is accumulated
itself. as user time.
There is no overflow limit for the • Elapsed time might not be correct
fields in the tms structure. if the processor's internal clock has
been reset.
Can return extended errors.
tzset()
Sets the time-zone conversion
information. Refer to ctime().
utime() Can return extended errors. FDM set.The file access time is not
Sets file access and modification updated by the FILE_OPEN_
times. procedure.
wcsftime()
Converts a date and time to a wide
character string. Refer to
strftime().
ADDDSTTRANSITION
Allows the super ID to add an entry to the daylight-saving
time (DST) transition table.
CANCELPROCESSTIMEOUT
Cancels a process-time timer previously initiated by a call
to the SIGNALPROCESSTIMEOUT procedure.
CANCELTIMEOUT
Cancels a process-time timer previously initiated by a call
to the SIGNALTIMEOUT procedure.
COMPUTEJULIANDAYNO
Converts a Gregorian calendar date on or after January
1, 0001, to a Julian day number.
COMPUTETIMESTAMP
Converts a Gregorian calendar date into a 64-bit Julian
timestamp.
CONVERTPROCESSTIME
Converts the process time returned by the PROCESSTIME,
MYPROCESSSTIME, and PROCESSINFO procedures into
hours, minutes, seconds, milliseconds, and microseconds.
CONVERTTIMESTAMP
Converts a Greenwich mean time (GMT) timestamp to
or from a local-time-based timestamp.
CPUTIMES
Returns the amount of time since system load that a given
processor has spent in the following states: process busy,
interrupt busy, and idle.
INTERPRETINTERVAL
Converts a fixed variable containing a number of
microseconds into a combination of days, hours, minutes,
seconds, milliseconds, and microseconds.
INTERPRETJULIANDAYNO
Converts a Julian day number to the year, month, and
day.
INTERPRETTIMESTAMP
Converts a 64-bit Julian timestamp into a Gregorian date
and time of day.
JULIANTIMESTAMP
Returns either a Julian timestamp or the number of
microseconds elapsed since the last system load.
MYPROCESSTIME
Returns the process execution time of the calling process.
PROCESS_GETINFO_
Obtains information, including the execution time, about
a specified process.
SETLOOPTIMER
Enables you to limit the processor time a process is
allowed.
SETSYSTEMCLOCK
Allows you to change the system clock.
SIGNALPROCESSTIMEOUT
Sets a timer based on process execution time.
SIGNALTIMEOUT
Sets a timer to a given number of units of elapsed time.
TIME
Provides the current date and time in integer form.
TIMESTAMP
Provides the internal form of the interval clock of the
processor where the application is running.
Topic Content
“Common and Unique Characteristics” (page 164) Summary of the differences between UNIX and OSS
interprocess communication.
“Interprocess-Communication Interoperability” (page 165) Summary of OSS and Guardian processes ability to
communicate using OSS and Guardian
interprocess-communication methods
“OSS Interprocess-Communication Functions” (page 184) List of each OSS interprocess-communication function
with notes about its OSS implementation and its use when
called from Guardian processes.
Available Methods
The OSS application program interface (API) provides access to the sockets, pipes, FIFOs, shared
memory, semaphores, and message queues found on most UNIX systems. An OSS application
also has access to Guardian APIs that provide additional interprocess-communication methods
such as Guardian sockets and the Guardian requester/server interface known as the $RECEIVE
file. Some of the OSS and Guardian interprocess communication methods also allow OSS processes
to communicate with Guardian processes.
Table 6-1 (page 163) lists the interprocess-communication methods available in Open System
Services using only OSS APIs, and the capabilities of each relevant to communication between
processors and nodes. The methods are listed in approximate decreasing order of usage on UNIX
systems.
Table 6-1 Interprocess Communication Using OSS APIs
IPC method Within a processor Between processors Between Expand With other systems
nodes
Table 6-2 lists the interprocess-communication methods available to an OSS process using mixed
OSS and Guardian APIs, and the capabilities of each relevant to communication between
processors and nodes. The methods are listed in an order consistent with Table 6-1.
Table 6-2 Interprocess Communication Using OSS and Guardian APIs
IPC method Within a processor Between processors Between Expand With other systems
nodes
Interprocess-Communication Interoperability
OSS and Guardian processes can communicate as described in the following subsections:
• “Using Guardian AF_INET and AF_NET6 Sockets, and OSS AF_INET and AF_INET6 Sockets”
(page 165)
• “Using AF_UNIX Sockets” (page 176)
• “Using FIFOs” (page 178) (named pipes)
• “Using Guardian Shared Memory and Semaphores” (page 178)
• “Using the $RECEIVE File” (page 179).
Guardian processes can use OSS sockets APIs, with the restrictions described in Table 6-3
(page 185). The table includes a short description of the OSS sockets functions.
OSS and Guardian processes cannot communicate using message queues, because only OSS
processes can call the message queue functions. OSS and Guardian processes cannot use AF_UNIX
sockets through the Guardian sockets API because Guardian sockets do not support the AF_UNIX
address family.
Using Guardian AF_INET and AF_NET6 Sockets, and OSS AF_INET and AF_INET6
Sockets
OSS and Guardian processes can communicate within the same node and between nodes or
systems using either:
• Guardian AF_INET or AF_INET6 sockets functions and semantics
NOTE: These examples use the AF_INET sockets functions, which provide an interface to
NonStop TCP/IP. The programs could also be written using the AF_INET6 sockets functions to
interface to NonStop TCP/IPv6. For information and examples of AF_INET6 sockets usage, refer
to the TCP/IP Programming Manual.
The server program in Example 6-1 is compiled as a linked program file named server2 that
is secured for execution in the current working directory. The requester program in Example 6-2
is compiled as a linked program file named requester2 that is secured for execution in the
current working directory.
The server process can be started in the background from the OSS shell using the command:
run ./server2 &
After you start the server process, the requester process in Example 6-2 can be started in the
foreground from the OSS shell using the command:
./requester2
Alternatively, both processes can be started in the foreground from separate terminal sessions.
The following sample dialog illustrates the processes run from two terminal sessions. The server
terminal session for the program in Example 6-1 appears as:
/home/software/chrisbl/cabpubs: ./server2
Server starting
Message received = hello
Message received = goodbye
Server stopping
/home/software/chrisbl/cabpubs:
while the requester terminal session for the program in Example 6-5 appears as:
/home/software/chrisbl/cabpubs: ./requester2
Requester starting
?hello
Read 6 bytes back from server
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
}
/* Get server port from the command line or use default 12345 */
if (argc > 1)
addr.sin_port = (short)atoi(argv[1]); /* use command line arg */
else
addr.sin_port = 12345; /* use default */
/* add fd to fd set */
fdcount++;
FD_SET(newfd, &fdset);
if (newfd > highfd)
highfd = newfd;
}
else /* else fd is an existing connection */
{
if ((bytesread = recv(fd, msg_buff, BUFF_LEN, 0)) <= 0)
{
/* if recv error then exit(1) */
if (bytesread < 0)
{
printf("recv() call failed [errno %d]\n", errno);
exit(1);
}
else /* bytesread == 0 ... peer closed connection */
{
close(fd);
fdcount--;
FD_CLR(fd,&fdset);
}
}
else /* data received */
{
msg_buff[bytesread] = '\0'; /* make string
NULL-terminated */
printf("Message received = %s", msg_buff);
#include <unistd.h>
#include <fcntl.h>
#include <tal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
printf("Requester starting\n");
/* Prompt user, read data, send data to server and wait for reply */
while (1) {
NOTE: These examples use the AF_INET sockets functions, which provide an interface to
NonStop TCP/IP. The programs could also be written using the AF_INET6 sockets functions to
interface to NonStop TCP/IPv6. For information and examples of AF_INET6 sockets usage, refer
to the TCP/IP Programming Manual.
The server program in Example 6-3 is compiled as a linked program file named server2g that
is secured for execution in the current working directory. The requester program in Example 6-2
is compiled as a linked program file named requester2 that is secured for execution in the
current working directory.
The server process can be started in the background from the OSS shell using the command:
run ./server2g &
After you start the server process, the requester process in Example 6-2 can be started in the
foreground from the OSS shell using the command:
./requester2
Alternatively, both processes can be started in the foreground from separate terminal sessions.
The following sample dialog illustrates the processes run from two terminal sessions. The server
terminal session for the program in Example 6-3 appears as:
/home/software/chrisbl/cabpubs: ./server2g
Server starting
Message received = hello
Message received = goodbye
Server stopping
/home/software/chrisbl/cabpubs:
while the requester terminal session for the program in Example 6-5 appears as:
#include <unistd.h>
#include <fcntl.h>
#include <tal.h>
#include <cextdecs.h(AWAITIOX,FILE_CLOSE_)>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#define NOWAIT 1
#define SYNC 1
#define FOREVER -1L
#define IDLE_PERIOD 6000 /* 60 seconds = 6000 x 0.01 second */
/* Get server port from the command line or use default 12345 */
if (argc > 1)
addr.sin_port = (short)atoi(argv[1]); /* use command line arg */
else
addr.sin_port = 12345; /* use default */
listenfd = fd;
Compatibility Mode
Sockets created in compatibility mode have these characteristics and behaviors, which are the
same as the characteristics and behaviors for AF_UNIX Release 1 sockets:
• If a relative name is passed to connect() then subsequent getpeername() calls return
that same relative name. That is, whatever pathname is passed to connect() is returned,
byte-for-byte, in subsequent calls to getpeername(), including path names beginning
with /E/local_system/ and names containing /./ or /../.
• If the file to which a socket is bound is removed or renamed, calls to getsockname() fail
with the error FE_ENOENT.
• If the file to which a datagram socket is bound is removed or renamed, and then a send
operation is performed on the socket, a recvfrom() or recvmsg() call on the receiving
socket returns a null address.
• A call to listen() with a backlog parameter less than or equal to 0 (zero) causes
subsequent connect() calls to fail with the ECONNREFUSED error unless the socket has
a pending accept() call.
You can create sockets in compatibility mode using one of these methods:
• Use the default transport-provider name. For systems running AF_UNIX Release 2 software,
the default AF_UNIX transport-provider name is $ZPLS, which results in sockets created in
compatibility mode.
• Use the Guardian DEFINE =_AFUNIX_PROCESS_NAME to specify $ZPLS as the transport
provider name. This Guardian define must be a MAP DEFINE with a FILE attribute string
of the desired AF_UNIX transport-provider name. For example:
TACL> ADD DEFINE =_AFUNIX_PROCESS_NAME,CLASS MAP,FILE $ZPLS
or
OSH> add_define =_AFUNIX_PROCESS_NAME class=MAP file=\$ZPLS
NOTE: Although the name $ZPLS is used as a transport-provider name, $ZPLS is not a
process that runs on the system.
Portability Mode
Sockets created in portability mode have these characteristics and behaviors:
• If a relative name is passed to connect() then subsequent getpeername() calls return
the corresponding absolute name. That is, the absolute path name returned by
getpeername() has the /E/local_system/ prefix (if present) stripped, all symbolic
links resolved, all /./ strings suppressed, and all /../ strings resolved.
• If the file to which a socket is bound is removed or renamed, calls to getsockname()
continue to return the original absolute path name.
NOTE: Although the name $ZAFN2 is used as a transport-provider name, $ZAFN2 is not
a process that runs on the system.
Using FIFOs
OSS and Guardian processes can communicate using FIFOs:
• Within the same processor
• Between processors
• Between nodes (by way of the /E directory)
However, they cannot communicate using unnamed pipes. Unnamed pipes can only be used to
communicate between OSS processes.
#include <unistd.h>
#include <fcntl.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_, READUPDATEX, REPLYX, FILE_CLOSE_, \
AWAITIOX, FILE_GETINFO_)>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/* The server process opens its $RECEIVE file for nowait IO. */
retcode = FILE_OPEN_(
filename, /* filename */
(short)strlen(filename), /* filename length */
&fnum, /* file number returned */
0, /* access mode (r/w) */
0, /* exclusion mode (shared) */
NOWAITDEPTH, /* nowait depth (nowait enabled) */
RECVDEPTH, /* receive depth (1 msg) */
0); /* options (sys msgs enabled) */
if (retcode != 0) /* if error, exit(1) */
{
fprintf(stderr, "FILE_OPEN_() to %s failed\n", filename);
fprintf(stderr, "Return code = %d\n", retcode);
exit(1);
}
/* Read data from $RECEIVE ... handle system msgs and user msgs */
openers = 0;
while (1)
{
CC = READUPDATEX(fnum, /* file number */
msg_buff.data, /* msg buffer */
BUFF_LEN, /* length */
&bytesread); /* number of bytes read */
if (_status_ne(CC)) /* if error, exit(1) */
{
}
else /* else must be a user request */
{
msg_buff.data[bytesread] = '\0'; /* make string NULL-terminated */
printf("Message received = %s", msg_buff.data);
CC = REPLYX(msg_buff.data, bytesread); /* reply with data */
if (_status_ne(CC)) /* if error, exit(1) */
{
fprintf(stderr, "REPLYX() to %s failed\n", filename);
exit(1);
}
}
} /* end while (!done) */
}
#include <unistd.h>
#include <fcntl.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,FILE_CLOSE_, \
WRITEREADX,FILE_GETINFO_)>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
printf("Requester starting\n");
/* Prompt user, read data, send data to server and wait for reply */
while (1)
{
printf("?"); /* send prompt */
fgets(msg_buff, BUFF_LEN, stdin); /* read user input */
if (feof(stdin)) /* if EOF */
{
Performance Considerations
You can improve the performance of your applications with respect to interprocess communication
by following these recommendations.
For input and output in general:
• There can be delays due to the blocking nature of many input/output calls. It can take an
indeterminate amount of time to complete a blocked call. Use the select() function or
nonblocking input/output when indeterminate waits are not desirable. Refer to Example 6-1
(page 168) for an example of the use of the select() call.
For pipes and FIFOs:
• Whenever possible, keep processes that use pipes and FIFOs on the same processor. When
processes reside on the same processor, there is no message system traffic. When processes
reside on different processors, a message system I/O path is created, which slightly degrades
performance. However, keeping processes on different processors can provide better load
balancing and scalability for your applications.
• Make the size of the data buffer exchanged through pipes and FIFOs equal to or less than
the size of the PIPE_BUF system variable. A buffer the size of PIPE_BUF or smaller can be
written in one I/O operation.
An application can force the OSS file system to attempt to resize the buffer used for a specific
pipe or FIFO file by calling the write() or writev() function for a write of more than
PIPE_BUF bytes. If resizing occurs, subsequent reads of up to 52 kilobytes can occur in a
single operation. Because all pipes and FIFOs in a processor have buffers allocated from a
fixed amount of memory, increasing the buffer size for one pipe or FIFO to improve its
throughput reduces the number of pipes and FIFOs that can exist simultaneously in that
processor.
For semaphores:
• Include deadlock-avoidance techniques in your applications.
For sockets:
• OSS AF_UNIX Release 2 sockets have improved performance over AF_UNIX Release 1 sockets
because AF_UNIX Release 2 sockets have fewer system processes involved in the delivery
NOTE: Some functions also have reentrant versions. For a complete list of supported functions,
including information about RVU support for each function, see Appendix A (page 389).
Table 6-4 (page 188) displays information about functions useful when managing interprocess
communication. The columns of the table contain the same kinds of information as in Table 6-3.
Table 6-3 OSS Interprocess-Communication Functions
OSS Function OSS Notes Guardian Notes
msgctl() Can return extended errors. Sets errno to the ENOTOSS value
Performs message queue control when called from a Guardian process.
operations.
msgget() Can return extended errors. Sets errno to the ENOTOSS value
Creates or returns the identifier for a when called from a Guardian process.
message queue.
msgrcv() Can return extended errors. Sets errno to the ENOTOSS value
Reads a message from a message when called from a Guardian process.
queue.
msgsnd() Can return extended errors. Sets errno to the ENOTOSS value
Sends a message to a message queue. when called from a Guardian process.
popen() Can return extended errors. Sets errno to the ENOTOSS value
Initiates a pipe to a process. when called from a Guardian process.
semctl() Can return extended errors. Sets errno to the ENOTOSS value
Performs semaphore control when called from a Guardian process.
operations.
semget() Can return extended errors. Sets errno to the ENOTOSS value
Creates a new semaphore set ID or when called from a Guardian process.
returns the ID of an existing
semaphore set.
semop() Can return extended errors. Sets errno to the ENOTOSS value
Performs semaphore operations. when called from a Guardian process.
shmat() Can return extended errors.Attaches Sets errno to the ENOTOSS value
Attaches a shared memory segment only flat, not selectable, memory when called from a Guardian process.
to the address space of the calling segments.
process. A shared memory segment must be
aligned on a region boundary. A
region is 32 MB of virtual memory.A
process can attach no more than 15
segments at one time.
Does not support read-only access to
shared memory.Memory segments
are not propagated to a child process
by any of the exec, tdm_exec, or
tdm_spawn sets of functions or when
the child resides in a different
processor from the parent.
shmctl() Can return extended errors. Sets errno to the ENOTOSS value
Performs shared memory control Operates only on flat, not selectable, when called from a Guardian process.
operations. memory segments.
shmdt() Can return extended errors. Sets errno to the ENOTOSS value
Detaches a shared memory segment. Detaches only flat, not selectable, when called from a Guardian process.
memory segments.
shmget() Can return extended errors. Sets errno to the ENOTOSS value
Creates a new shared memory Operates only on flat, not selectable, when called from a Guardian process.
segment or returns the identifier of memory segments.
an existing shared memory segment.
Reuses no-longer-used shared
memory identifiers after a long time
elapses.
A shared memory segment is shared
through a Guardian swap file .If a
processor fails, the following is lost:
all information in the processor’s
shared memory table, all shared
memory segments for that processor,
and all swap files.
The maximum number of shared
memory identifiers is
SHMT_MAXENTRIES.
A shared memory segment can be 1
byte to 128 MB in size.
freeaddrinfo()
Frees a specified address information
structure previously allocated by
getaddrinfo().
freehostent()
Frees hostent structure previously
allocated by getipnodebyaddr or
getipnodebyname.
gai_sterr()
Aids applications in printing error
messages returned by
getaddrinfo().
getaddrinfo()
Converts hostnames and service
names into socket address structures.
getipnodebyaddr()
Gets a network host entry by address.
getipnodebyname()
Gets host information based on IP
node name.
getnameinfo()
Translates a protocol-independent
host address to a host name and gives
the service name.
if_freenameindex()
Frees dynamic memory allocated by
the if_nameindex function.
if_indextoname()
Maps an interface index to its
corresponding name.
if_nameindex()
Gets all interface names and indexes.
if_nametoindex()
Maps an interface name to its
corresponding index.
htonl()
Converts a 32-bit integer from host
byte order to Internet network byte
order.
htons()
Converts a 16-bit integer from host
byte order to Internet network byte
order.
inet_addr()
Constructs an integer Internet address
from a character string in Internet dot
notation.
inet_lnaof()
Extracts the local network address
from an Internet host address.
inet_makeaddr()
Constructs an integer Internet address
from an Internet network number and
a local network address.
inet_netof()
Extracts the network number from an
Internet host address.
inet_network()
Translates a character string in
Internet dot notation to an Internet
network address.
inet_ntoa()
Translates an integer Internet address
into a character string in Internet dot
notation.
inet_ntop()
Converts a binary internet address to
a character value.
inet_pton()
Converts a character string to an IPv4
or IPv6 binary address.
ntohl()
Converts a 32-bit integer from
Internet network byte order to host
byte order.
ntohs()
Converts a 16-bit integer from
Internet network byte order to host
byte order.
AWAITIO[X]
Checks for completion of nowait operations pending on
one or all Guardian file opens (using file numbers),
including operations on a server process file.
CANCEL
Cancels the oldest outstanding nowait operation on a
specified Guardian open, such as a server process file.
CANCELREQ
Cancels a a specific outstanding nowait operation on a
specified Guardian file open, such as a server process file.
FILE_CLOSE_
Closes a Guardian file open, such as a server process file.
FILE_GETINFO_
Provides error information and characteristics about a
Guardian file open, such as a server process file.
FILE_GETRECEIVEINFO_
Returns information about the last message read from the
$RECEIVE file of the calling process.
FILE_OPEN_
Establishes a Guardian file open with a file number. Can
be used by:
• A requester process to open a server process file
• A server process to open its $RECEIVE file
READUPDATE[X]
Reads a message from the $RECEIVE file of a server
process, expecting to reply to the message sender in a
subsequent call to REPLY[X].
REPLY[X]
Replies through the $RECEIVE file of a server process to
a message that was previously read by READUPDATE[X].
SEGMENT_USE_
Makes a selectable segment current (a flat segment need
not be made current). It also returns the last selectable
segment in use.
WRITEREAD[X]
Sends a message to a server process and waits for a reply
(assuming waited I/O).
CONTROL
Issues CONTROL operations to a process that simulates
an input/output device.
CONTROLBUF
Issues CONTROLBUF operations to a process that
simulates an input/output device.
MESSAGESTATUS
Checks the $RECEIVE file of a server process to see
whether a specific message has been canceled.
READ[X]
Reads information from the $RECEIVE file of a server
process.
SETMODE
Issues SETMODE functions to a process that simulates
an input/output device.
SETMODENOWAIT
Performs the same functions as SETMODE but in a nowait
manner.
SETPARAM
Issues SETPARAM operations to a process that simulates
an input/output device.
WRITE[X]
Sends a message to a server process and waits for a reply
(assuming waited input/output).
Topic Content
“Common and Unique Characteristics” (page 195) Summary of the differences between OSS and UNIX I/O.
“I/O Interoperability” (page 195) The objects on which you can use OSS I/O functions and
Guardian procedures.
“Tape I/O” (page 196) Tape I/O using pax and the Guardian API.
“Terminal I/O” (page 198) Terminal I/O using the OSS API.
“Using OSSTTY to Redirect Input and Output to Guardian Using the OSSTTY facility to redirect the OSS standard
Objects” (page 202) files to Guardian processes and EDIT files.
“Printer I/O” (page 214) Printing OSS files using the OSS and Guardian APIs.
“OSS I/O Management Functions” (page 221) List of each OSS I/O function with notes about its OSS
implementation and its use on Guardian objects.
“Guardian I/O Management Procedures” (page 222) List of each Guardian I/O procedure with notes about its
use on OSS objects.
The major difference between managing I/O with the OSS API and managing I/O with the UNIX
operating system is that the OSS environment offers limited I/O features. For greater control
over most I/O operations, you must use Guardian procedures.
I/O Interoperability
OSS terminal I/O functions operate only on the terminal device /dev/tty. The functions
cfsetispeed() and cfsetospeed() have no effect on the network terminals (they affect
only local terminals). The function tcsetattr affects both the Telserv and OSSTTY terminals.
There are no OSS I/O functions that apply to printers or tape drives.
Guardian I/O procedures operate only on Guardian devices.
FILE *fpout;
#define MAXLINE 132
char paxbuf[MAXLINE];
char line[MAXLINE];
Terminal I/O
The only terminals supported by Open System Services are Telserv windows and OSSTTY
windows, so terminal I/O is the same as that for a UNIX network terminal. OSS also supports
local terminals through OSSTTY, although OSSTTY has the look and feel of a remote terminal.
The OSS terminal interface is described in detail in the termios(4) and tty(7) reference pages
either online or in the Open System Services System Calls Reference Manual.
Terminal Parameters
Most of the control characters in the c_cflag field of the termios structure in the termios.h
header file are ignored. The HUPL flag of the c_flag field affects both local and remote terminals.
For more information, refer to the termios(4) and tty(7) reference pages either online or
in the Open System Services System Calls Reference Manual.
Also, the following functions have no effect:
• cfsetispeed()
• cfsetospeed()
• csendbreak()
Control Characters
The default values of control characters are defined in the termios.h header file. The definitions
are in the array specified by the c_cc field of the termios structure. According to the standards
that the OSS environment conforms to, these values can vary from implementation to
implementation.
The OSS API has two terminal I/O modes: canonical mode, in which input data is assembled
into lines, and noncanonical mode, in which input data is not assembled into lines.
Canonical mode control characters, their default values, associated flags, and indexes into the
array specified by the c_cc field of the termios structure are shown in Table 7-1.
Noncanonical mode control characters, their default values, associated flags, and indexes into
the array specified by the c_cc field of the termios structure are shown in Table 7-2.
Table 7-2 Noncanonical Mode Control Characters and Associated Flags in termios.h
Control Character Default Value Associated Flag Index in c_cc
Because OSSTTY has no control over the interface from which it reads data, the STOP and START
characters in the stream are discarded. OSSTTY supports flow control for applications when
directed to do so programmatically through tcflow() (TCION and TCIOFF flags).
OSSTTY supports three standard qualifiers: #stdin, #stdout, and #stderr. OSS applications
can redirect their standard input, standard output, and standard error to OSSTTY by using these
qualifiers:
Qualifier Description
/G/name/#stdin Redirects standard input data to the OSSTTY process identified by name.
/G/name/#stdout Redirects standard output data to the OSSTTY process identified by name.
/G/name/#stderr Redirects standard error data to the OSSTTY process identified by name.
OSSTTY, in turn, redirects data from these qualifiers to Guardian objects that you specify when
starting OSSTTY.
Starting OSSTTY
You can start OSSTTY either from the TACL prompt or through the OSH command line. The
following subsections present simple forms of the commands for starting OSSTTY. For detailed
descriptions of all OSSTTY run-time options, see the Open System Services Management and
Operations Guide.
Note: The program must be started with the log file name as an
argument.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <tal.h>
#include <cextdecs(FILE_OPEN_, OPENEDIT_, READUPDATEX, REPLY, \
CLOSEALLEDIT, FILE_PURGE_, FILE_GETINFO_, WRITEEDIT)>
/* public data */
short rcv_fd;
short U_data[4*1024];
short edit_fd ;
short rcv_cnt;
/* public functions */
/* private functions */
void user_message(void);
void system_message(void);
Procedure Description
SH $name Starts a named OSSTTY process and an OSS shell process, setting up the necessary
redirection.
UNSH $name Removes the specified previously defined OSSTTY/OSS shell environment.
TELL $name command-string Sends a single command to the specified previously defined OSSTTY/OSS shell
environment. Also displays any output from a prior command.
PRINT $name Displays any output from the specified previously defined OSSTTY/OSS shell
environment.
BE $name Enters interactive mode with the specified previously defined OSSTTY/OSS shell
environment. The user can enter commands and receive responses repeatedly,
until <Ctrl-y> is entered. Entering <Ctrl-y> causes the procedure to exit interactive
mode, but leaves the OSSTTY/OSS shell environment intact.
RESET $name Informs a previously defined OSSTTY environment that there is an interactive
prompt outstanding. (Used in the event that there is a prompt outstanding, but
the procedures do not recognize the prompt.)
/G/SYSTEM/ADIR
|otherwise|
#output Extraneous input -- terminating.
#output
#pop pname
#return
] == end case
|2|
#output Expecting a nonexistent process name -- terminating.
#output
#pop pname
#return
] == end case
#set pname [#shiftstring /down/ [pname]]
#chardel pname 1 for 1
[#push [pname]^in^buf [pname]^out^buf [pname]^prompt^buf [pname]^need^prompt
[pname]^status stdin stdout
] == end push
#set stdin /G/[pname]/#stdin
#set stdout /G/[pname]/#stdout
sink [#newprocess $system.system.osstty /name $[pname], nowait,
inv [pname]^in^buf dynamic, outv [pname]^out^buf/
-server]
sink [#newprocess $system.system.osh /status [pname]^status, nowait/
-p /bin/sh < [stdin] > [stdout] 2> [stdout]]
#set [pname]^need^prompt -1
#pop pname stdin stdout
|2|
#output Expecting a process name -- terminating.
#output
#unframe
#return
] == end case
#set name [pname]
#chardel name 1 for 1
[#if not [#variableinfo /existence/ [name]^in^buf] |then|
#output Nothing to get rid of.
#output
#unframe
#return
] == end if
[#if [#processexists [pname]] |then|
#set prog [#fileinfo /file/ [#processinfo /programfile/
[pname]]]
[#if not [#match osstty [prog]] |then|
#output [pname] is not an OSSTTY process.
#output
#unframe
#return
] == end if
#set [pname]^out^buf
#append [pname]^in^buf [#rest]
sink [#wait [pname]^out^buf [pname]^status]
#set [pname]^need^prompt -1
print $[pname]
#set done 0
[#loop |while| not [done] |do|
#inputv in^line [pname]^prompt^buf
[#if [#inputeof] |then|
#set done -1
|else|
#set [pname]^out^buf
#appendv [pname]^in^buf in^line
#set [pname]^need^prompt -1
sink [#wait [pname]^out^buf [pname]^status]
] == end if
] == end loop
#unframe
Printer I/O
The OSS API has no function that accesses printers or spoolers directly. You cannot write directly
to printers with the OSS API. To print from an OSS program or get information about a print
job, you access the Guardian spooler with the lp or lpstat utility.
You can, however, write OSS files and output directly to a printer or to the Guardian spooler
using the Guardian API, as described later in this subsection.
if(argc < 2) {
fprintf(stderr, "Usage: lpopen <pathname>\n");
exit(1);
}
/* Open the input file. */
if((fpin = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "Can't open %s\n", argv[1]);
exit(1);
}
/* Create a string for popen() with the name of the file to be
printed in the title. */
sprintf(lpbuf, "lp -t %s", argv[1]);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(FILE_OPEN_,FILE_CLOSE_,\
SPOOLSTART, SPOOLCONTROL,\
SPOOLWRITE,SPOOLEND)>
if (argc > 2)
pathname = argv[2];
else
pathname = __FILE__;
/* Get the Guardian printer filename and the name of the file to print.*/
if (argc > 1)
printer = argv[1];
else
printer = "$s.#default";
if (argc > 2)
pathname = argv[2];
else
pathname = "/usr/include/stdio.h";
if((infile = fopen(pathname, "r")) == 0) {
perror("Can't open file");
exit(1);
}
retcode = FILE_OPEN_(printer, /* name of Guardian printer */
(short)strlen(printer), /* printer name length */
&filenum, /* file number returned */
2, /* open for write access */
1, /* open for exclusive use */
);
/* Check if open was successful. */
if (retcode != 0) {
fprintf(stderr, "Can't open %s\n", printer);
fprintf(stderr, "retcode = %d\n", retcode);
exit(1);
}
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 389).
Table 7-3 OSS I/O Functions
OSS Function OSS Notes Guardian Notes
cfgetispeed()
Gets the input baud rate for a
terminal.
cfgetospeed()
Gets the output baud rate for a
terminal.
ctermid() If the parameter is a null pointer, the For Guardian TNS processes, it returns
Generates the pathname for a string is stored in an internal static an empty string and errno is set to
controlling terminal. area and the address is returned. The ENOTOSS.
next call to this function overwrites
the contents of the internal static area.
Can return extended errors.
CHECKSETMODE
Allows the primary process of a process pair to propagate
SETMODE operations to the backup process of the pair.
CONTROL
Performs device-dependent I/O operations.
CONTROLBUF
Performs device-dependent I/O operations that require
a data buffer.
DEVICE_GETINFOBYLDEV_
Obtains the logical and physical attributes of a device.
LABELEDTAPESUPPORT
Provides a way for nonprivileged programs to determine
whether labeled-tape processing is enabled on the system.
SETMODE
Sets device-dependent procedures.
SETMODENOWAIT
Sets device-dependent procedures in a nowait manner
on nowait files.
Topic Content
“Common and Unique Characteristics” (page 225) Summary of the differences between OSS and UNIX
logging mechanisms.
“Logging Interoperability” (page 226) The processes in which you can use OSS logging
functions.
“How to Log Information With the OSS API” (page 226) How to use the OSS logging functions.
“OSS Logging-Mechanism Functions” (page 232) List of each OSS logging mechanism function with notes
about its OSS implementation and use on Guardian
processes.
Logging Interoperability
You can call OSS logging functions from a Guardian module that is part of an OSS process. You
cannot use the LOG_PID option of the openlog() function on a Guardian process.
OSS processes have the same access to EMS procedures as do Guardian processes. Both OSS
processes and Guardian processes can:
• Call any of the EMS procedures for constructing events
• Open collectors and send them events using the WRITEREAD or WRITEREADX procedures
• Start a consumer distributor and receive EMS event messages
An OSS process must use Guardian file-system and process-control procedures to start and
communicate with the consumer distributor. For further information about using EMS, refer to
the EMS Manual.
The values of these parameters appear in an OSS logging message in the following order:
facility level[,PID = pid] (identity) : message-text
The content of message-text is pointed to by the message parameter.
The values of the logopt and maskpri parameters do not appear in OSS log messages.
The OSS process ID appears in the message if you specify the LOG_PID option in the logopt
parameter of the openlog() function, as described in “logopt Parameter” (page 229).
Specifying a Collector
A user of your application can specify an EMS collector process from the shell by setting the OSS
environment variable EMS_COLLECTOR to the desired collector. You must export the variable
before using the collector. You use the export command to both set the value of the variable and
export it as follows:
export EMS_COLLECTOR=\$COL
In this example, the backslash (\) is required to prevent the shell from interpreting $COL as a
shell variable, and $COL represents the name of the collector.
You can have event messages sent to $0, the local primary collector, if, for some reason a message
cannot be sent to the collector specified by a user with the EMS_COLLECTOR environment variable.
To send events to $0 as a backup, specify the LOG_CONS option in the logopt parameter of the
openlog() function, as described in “logopt Parameter” (page 229).
LOG_ALERT 6 ALERT
LOG_CRIT 7 CRITICAL
LOG_ERR 8 ERROR
LOG_WARNING 9 WARNING
LOG_NOTICE 10 NOTICE
LOG_INFO 11 INFO
facility The part of the system you specify as having generated the event message
facility Parameter
The facility parameter enables you to specify the part of the system that generates the event
message. The default facility is LOG_USER; this is the only facility that has meaning in the OSS
environment. Although authorization, demon, kernel, and mail facilities are in the Guardian
environment and do not generate OSS events or messages, you can use the openlog() function
to specify any facility.
The openlog() function changes the default facility only if the facility parameter is nonzero.
The value of LOG_KERN is 0, so to change the facility to LOG_KERN, change its value to 1 using
the exclusive-or operator, as shown in the following example:
openlog(LOG_KERN | 1);
The facility parameter is also displayed as a string in the OSS log message. The facilities and
their strings are listed in Table 8-5.
Table 8-5 OSS Logging Facilities
Facility Message String Description
LOG_AUTH AUTH Messages generated by the login, su, and other shell
commands or utilities belonging to a user authorization
system.
identity Parameter
The identity parameter enables you to specify an event subject string to appear in the OSS
log message. The default subject string is “syslog”.
logopt Parameter
The logopt parameter enables you to specify logging options. You can specify any set of options.
To specify more than one option, separate the options with the OR operator (|), as in the following
example:
openlog(LOG_CONS | LOG_PID);
The default value of logopt is LOG_ODELAY, which waits until the first message is logged before
opening a collector. Table 8-6 (page 229) lists the logging options.
Table 8-6 OSS Logging Options
Option Description
LOG_CONS Sends the event message to the local primary collector, $0, if the message cannot be
sent to the collector specified by the EMS_COLLECTOR environment variable
LOG_ODELAY Waits until the first message is logged before opening the connection to the collector
process
LOG_PID Includes the OSS process ID of the calling process in each event message
NOTE: Do not use the LOG_PID option on a Guardian process. If you do, the syslog()
function will call the openlog() function and fail with Guardian trap 5, because Guardian
processes have no OSS process ID.
Logging a Message
You call the syslog() function whenever you want to log a message from your program. For
suggestions about the kinds of events and messages to log, refer to the EMS Manual.
syslog( LOG_DEBUG
, "%4d Fahrenheit -- %6.1f Centigrade "
, fahr
, (5.0/9.0)*(fahr - 32 ) );
#include <fcntl.h>
#include <syslog.h>
#include <stdio.h>
if(argc < 2) {
syslog(LOG_ERR, "Usage: syslog pathname\n");
exit (1);
}
/* If the file cannot be opened, log an error message and exit. */
if((fd = open(argv[1], O_RDONLY)) < 0) {
syslog(LOG_ERR, "Can't open %s\n", argv[1]);
exit(1);
}
/* If the file is not at least 512 bytes long, log a read error. */
if(read(fd, buf, 512) != 512) {
syslog(LOG_ERR, "Read error %m on key daemon file.\n");
exit(1);
}
close(fd);
/* Write a "Daemon X stopped" message. */
syslog(LOG_INFO,"Daemon X stopped.\n");
/* Close connection to EMS collector process */
closelog();
exit(0);
}
Closing a Collector
To close the connection to the EMS collector process opened by openlog() or syslog(), call
the closelog() function.
facility ZOSS-TKN-FACILITY
identity ZOSS-TKN-IDENT
level ZOSS-TKN-LEVEL
message ZEMS-TKN-TEXT
The OSS process ID value displayed in log messages corresponds to the value of the
ZOSS-TKN-PID token. This parameter is included in the event message only if LOG_PID is
specified to openlog().
closelog()
Closes the collector process that was
opened by openlog() or syslog().
perror()
Writes a message explaining the last
error encountered by a library
function.
setlogmask()
Sets the EMS event log mask.
Communications Subsystems
A communications subsystem provides users with access to a set of communications services.
It consists of one or more processes running on a system and possibly a protocol module running
on a communications controller.
Examples of HP communications subsystems include Transmission Control Protocol/Internet
Protocol (TCP/IP), HP Tandem LAN Access Method (TLAM), X.25 Access Method (X25AM),
SNAX Extended Facility (SNAX/XF), Open Systems Interconnection/Application Services (OSI/AS),
and Open Systems Interconnection/Message Handling System (OSI/MHS).
You can access HP communications subsystems from OSS applications, but for some operations
you must use Guardian I/O procedures. You will probably want to use nowait I/O, which allows
a program to continue executing in parallel with read or write operations. Nowait I/O is not
available using OSS I/O functions. You also need to read the $RECEIVE file if the subsystem
sends status messages to $RECEIVE. Reading the $RECEIVE file requires using Guardian
procedures.
Because you have to use Guardian procedures for significant portions of your program, it is
easier if you use Guardian I/O procedures exclusively to access communications subsystems
instead of mixing Guardian I/O procedures and OSS I/O functions.
For more information about HP communications subsystems, see the manual sets that describe
the subsystems you need to access. These manual sets can include introductory, configuration,
programming, and reference manuals.
HP NonStop SQL/MP
The HP NonStop SQL/MP relational database management system uses the standard Structured
Query Language (SQL) to describe and manipulate data. SQL/MP can be used for online
transaction processing, decision support systems, scalable electronic commerce applications, and
other business applications.
You can access SQL databases from an OSS program as you do from a Guardian program, using
embedded SQL statements. You can also get information about SQL objects, catalogs, and
programs using Guardian procedure calls. However, in the Guardian environment, you must
use several products to compile, link, and optimize a program. In the OSS environment, you can
use the c89 (but not the c99) utility to perform all of these functions in a single c89 command.
You do need to invoke the SQL compiler as well as the C compiler in the c89 command, and
the SQL compiler must be version 315 or newer. For information about the c89 utility, see the
c89(1) reference page either online or in the Open System Services Shell and Utilities Reference
Manual.
For more information about writing OSS application programs that access SQL/MP databases,
see the SQL/MP Programming Manual for C.
HP NonStop SQL/MX
The HP NonStop SQL/MX relational database management system uses the standard Structured
Query Language (SQL) to describe and manipulate data. SQL/MX can be used for online
transaction processing, decision support systems, scalable electronic commerce applications, and
other business applications.
You can access SQL databases from an OSS program using embedded SQL statements. You can
also get information about SQL objects, catalogs, and programs. You can use the c89 or the c99
utility to compile, link, and optimize a program in a single c89 or c99 command.
You do need to invoke the SQL/MX compiler as well as the C compiler in the c89 or the c99
command. For information about the c89 utility, see the c89(1) reference page either online
or in the Open System Services Shell and Utilities Reference Manual. For information about the c99
utility, see the c99(1) reference page either online or in the Open System Services Shell and Utilities
Reference Manual.
For more information about writing OSS application programs that access SQL/MX databases,
see the SQL/MX Programming Manual for C and COBOL.
HP NonStop TS/MP
HP NonStop Transaction Services/MP (TS/MP) provides online transaction processing. TS/MP
can create and monitor OSS servers, but it does not support OSS requesters.
An OSS server process must read its $RECEIVE file to get messages from requester processes.
To read the $RECEIVE file, you must use Guardian procedures.
HP NonStop TMF
HP NonStop Transaction Management Facility (TMF) provides transaction protection, database
consistency, and database recovery. It does this by managing database transactions, keeping
track of database activity through the use of audit trails, and providing database recovery methods.
TMF cannot audit, or protect, OSS files. You can access protected Guardian files from the OSS
environment, but you must use Guardian procedures to do so.
For more information about the Guardian procedures you can use to access files protected by
the TMF product, see the TMF Application Programmer’s Guide.
Topic Content
“Common and Unique Characteristics” (page 239) Summary of the differences between OSS and UNIX
security management
“Functions Available for Security Management” (page 240) Describes the C functions available for managing the
security of OSS objects
“Security Auditing of OSS files” (page 243) Describes the application program interfaces (APIs) that
can be audited when performing OSS file access and
process control activities
“Example of Managing file Ownership” (page 246) Provides a simple example of managing file ownership
in the OSS environment
“Using OSS Access Control Lists (ACLs)” (page 249) Describes OSS access control lists and their use.
Figure 10-1 Major Components and Interfaces for OSS Security Management
acl() Changes file access permissions for a list of users and groups.
cuserid() Gets the user name associated with the real user ID of the current process.
fstat() Gets the OSS user ID for the owner of an open file.
fstat64()
getsid() Gets the group ID of the process that is the session leader of the specified process.
getgroups() Gets the list of groups to which the current process belongs.
getlogin() Gets the login name (user name) for the current terminal session.
getpass() Reads a string of characters (such as a password) from a terminal without echoing the
characters entered.
getppid() Gets the OSS process ID of the parent process for the calling process.
lstat() Gets the OSS user ID for the owner of a file or symbolic link.
lstat64()
mkdir() Creates a directory with specified access permissions and default OSS user ID and group
ID values.
setgrent() Resets the group name key to get group information from the group database.
setpgrp() Creates a new session when the calling process is not a process group leader, and sets
the process group ID of the calling process.
The Guardian environment provides separate procedures for managing Guardian process and
Guardian file security. Refer to the Security Management Guide for an overview of both Guardian
and OSS security interfaces and activities.
NOTE: To determine which RVUs support an OSS function, see Appendix A: Documented
OSS Functions (page 389).
Table 10-2 OSS Function Calls Audited When Used With Audited filesets
OSS Function Attributes or Actions Audited
acl() The number of ACL entries and the value of each changed ACL entry before and after
the call.
bind() For AF_UNIX sockets, the values of the access_mode parameter, the OSS user ID, group
ID, and rdev.
chmod() The values of the file mode before and after the call.
fchmod()
lchmod()
chown() The values of the OSS user ID, group ID, and file mode before and after the call.
fchown() Use on files in the /G directory is also audited.
lchown()
creat() For all files, the value of the file mode, the OSS user ID, the group ID, and rdev.
creat64() For regular files, the value of the open flags.
execl() The value of the OSS user ID and group ID.Use on files in the /G directory is also audited.
execle()
execlp()
execv()
execve()
execvp()
kill() The signal sent, the real OSS user ID and effective OSS user ID of the sender, the OSS
process ID or process group ID, the process handle, and the saved set OSS user ID of the
target process.
If the target process is a member of a process group, the audit information is logged for
all the processes affected by the call when those processes can be determined.
link() The name and the link count of the linked-to file, and the new filename.
mkdir() The value of the file mode, the OSS user ID, the group ID, and rdev.
mkfifo() The value of the file mode, the OSS user ID, the group ID, and rdev.
mknod() The value of the file mode, the OSS user ID, the group ID, and rdev.
open() The value of the open flags and the value of the file mode before and after the call.
open64() Use on files in the /G directory is also audited.
opendir() The value of the open flags and the value of the file mode before and after the call.
rmdir() For a link count of zero, the value of the file mode, the OSS user ID, the group ID, the
mtime, ctime, size, and rdev.
For a link count that is not zero, the value of the link count after the call.
setgid() The value of the real, effective, and saved-set group ID before and after the call.
setpgid() The value of the process-group ID before and after the call.
setpgrp() The value of the process-group ID before and after the call.
setregid() The value of the real, effective, and saved-set OSS group ID before and after the call
setsid() The value of the process-group ID before and after the call.
setreuid() The value of the real, effective, and saved-set OSS user ID before and after the call.
setuid() The value of the real, effective, and saved-set OSS user ID before and after the call.
symlink() The contents of the symbolic link and the value of the file mode, the OSS user ID, the
group ID, and rdev.
tdm_execve() The process name and the value of the OSS user ID and group ID.
tdm_execvpe() Use on files in the /G directory is also audited.
tdm_fork() The process name and the value of the OSS user ID and group ID.
tdm_spawn() The process name and the value of the OSS user ID and group ID.
tdm_spawnp() Use on files in the /G directory is also audited.
unlink() For a link count of zero, the value of the file mode, the OSS user ID, the group ID, the
mtime, ctime, size, and rdev.
For a link count that is not zero, the value of the link count after the call .
utime() The values of mtime, atime, and ctime before and after the call.
Use on files in the /G directory is also audited.
Table 10-3 Guardian Procedure Calls Audited When Used With Audited filesets
Procedure Call Attributes or Actions Audited
FILE_OPEN_ Resolution of a supplied pathname to a regular file in an audited fileset; use of an internal
SPT_FILE_OPEN OSS filename; all Guardian file audit attributes.
PROCESS_SPAWN_ Resolution of a supplied pathname to a regular file in an audited fileset; use of an internal
OSS filename; all Guardian file audit attributes.
Table 10-4 Guardian Procedure Calls Audited When Used for Process Control
Procedure Call Attributes or Actions Audited
FILE_OPEN_ The value of the open flags and the value of the file mode before and after the call
SPT_FILE_OPEN
PROCESS_SPAWN_ The process name and the value of the OSS user ID and group ID
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <grp.h>
#include <pwd.h>
/*
* Print out the group number in decimal followed by (groupname)
*/
void printgroup(gid_t groupid)
{
unsigned long lt; /* temp */
struct group *grpptr; /* pointer to group info */
void printsupgroups()
{
int ngroups; /* number of supplemental groups */
gid_t grouplist[NGROUPS_MAX]; /* list of group IDs */
int i;
gid_t gid;
Definitions
Control of access to data is a key concern of computer security. These definitions, based on the
Department of Defense Trusted Computer System Evaluation Criteria, explain the concepts of access
control and its relevance to OSS security features:
access
A specific type of interaction between a subject and an object that results in the flow of
information from one to the other. Subjects include persons, processes, or devices that cause
information to flow among objects or change the system state. Objects include files (ordinary
files, directories, special files, FIFOs, and so on) and IPC features (shared memory, message
queues, semaphores, and sockets).
access control list (ACL)
An access control list is a set of user.group, mode entries associated with a file that specifies
permissions for all possible combinations of user IDs and group IDs.
ACL entry
An entry in an ACL that specifies access rights for a file owner, owning group, group class,
additional user, additional group, or all others.
change permissions
The right to alter DAC information (permission bits or ACL entries). Change permission is
granted to object (file) owners and to privileged users.
discretionary access control (DAC)
A means of restricting access to objects based on the identity of subjects, groups to which
they belong, or both. The controls are discretionary because a subject with a certain access
permission is able to pass that permission (perhaps indirectly) to any other subject.
mode
Three bits in each ACL entry that represent read, write, and execute or search permissions.
privilege
The ability to ignore access restrictions and change restrictions imposed by security policy
and implemented in an access control mechanism. In OSS, the super ID is the only user ID
that can ignore access restrictions. However, the super ID and any member of the Safeguard
SECURITY-OSS-ADMINISTRATOR security group can change the ownership and access
permissions (standard UNIX permissions or ACL entries) of a file.
ACL Notation
Supported commands that manage ACLs recognize these symbolic representations:
[d[efault]:]u[ser]:[uid]:perm
[d[efault]:]g[roup]:[gid]:perm
[d[efault]:]c[lass]:perm
[d[efault]:]o[ther]:perm
An ACL entry prefixed with d: or default: can occur only in ACLs for directories. The prefix
indicates that the remainder of the entry is not to be used in determining the access rights to the
directory but instead is to be applied to any files or subdirectories created in the directory (see
“ACL Inheritance” (page 253)).
The uid and gid fields contain either numeric user or group IDs, or their corresponding character
strings from the authentication database and group database for the system.
The perm field indicates access permission either in symbolic form, as a combination of r, w, x,
and - (dash), or in numeric form, as an octal value of 0 through 7 representing the sum of 4 for
read permission, 2 for write permission, and 1 for execute permission.
class:perm CLASS_OBJ The maximum permissions granted to the file group class
Class Entry
The class ACL entry, which is a base ACL entry, was created to preserve compatibility with
programs that only use chmod(). Because of the class ACL entry, existing programs that use
chmod() can work with file that have ACL entries for optional users and optional groups in
addition to the owning group.
The class entry acts as an upper bound for file permissions. In an ACL that contains optional
group entries or optional user entries, the class entry specifies the maximum permissions that
can be granted to:
• Members of the owning group
• Any additional user entries (optional users)
• Any additional group entries (members of any optional groups)
The class entry is useful because it allows you to restrict the permissions for all of the other ACL
entries by changing only one ACL entry. If optional user or optional group ACL entries are
present, the chmod command changes the permissions of the class ACL entry instead of the
permissions of the owning group. This behavior allows programs that use the chmod command
to support files or directories that have permissions for additional users and groups.
The permissions for these entries in the parent directory, modified by the file-creation mode, the
umask, or both, become the permissions for the base ACL entries for a new file when the new
file inherits ACL entries from the parent directory:
• default:user::perm (DEF_USER_OBJ)
• default:group::perm (DEF_GROUP_OBJ)
• default:class:perm (DEF_CLASS_OBJ)
• default:other:perm (DEF_OTHER_OBJ)
These entries are sometimes referred to as base default ACL entries.
ACL Uniqueness
Entries are unique in each ACL. An ACL can contain only one of each type of base entry, and
only one entry for any given user or group ID. Likewise, an ACL can contain only one of each
type of default base entry and only one default entry for any given user or group ID.
ACL Inheritance
The permissions, including access control list entries, if any, for a newly created file are determined
by:
• Whether the fileset of the created file supports OSS ACLs
• Whether the system on which the process is running supports OSS ACLs
• Whether the parent directory of the created file contains default ACL entries
• The file-creation mode (mode)
• The process umask (umask)
If the fileset does not support OSS ACLs, the permissions of the created file are the mode
bitwise-ANDed with the complement of the umask.
• The default optional ACL entries for the parent directory of the created file are added to the
ACL of the created file as actual (nondefault) optional ACL entries.
• If the created file is a directory, all of the default ACL entries of the parent directory are
added to the ACL of the new directory. This behavior allows ACL entries to be inherited by
files and directories created under this new directory.
If both the fileset for the created file and the system in which the process is running support OSS
ACLs, and the parent directory for the created file does not have default ACL entries, the
permissions of the created file are the mode bitwise-ANDed with the complement of the umask.
If both the fileset for the created file and the system in which the process is running support OSS
ACLs, and the parent directory of the created file contains default ACL entries:
• The permissions for the base ACL entries of the created file or directory are determined by
a combination of the file-creation mode and the default base ACL entries of the parent
directory as follows:
• The default optional ACL entries for the parent directory of the created file are added to the
ACL of the created file as actual (nondefault) optional ACL entries.
• If the created file is a directory, all of the default ACL entries of the parent directory are
copied to the ACL of the new directory. This behavior allows default ACL entries to be
inherited by files and directories created under this new directory.
For more information about OSS NFS file system security, see the Overview of NFS for Open System
Services and the Open System Services NFS Management and Operations Guide.
Header file
The sys/acl.h header file defines the following constants to govern the number of entries per
ACL:
NACLENTRIES
The maximum number of entries per ACL, including base entries
NACLBASE
The number of base entries
For compatibility with HP-UX, the variable name NACLVENTRIES is provided as an alias for
NACLENTRIES.
The ACL structure struct acl is also defined and includes these fields:
int a_type; /* type of entry */
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <acl.h>
#include <errno.h>
#define READPERM 4
#define CALCCLASS 1
{
int i;
printf("%s\n",header);
for (i= 0; i < count; i++) {
printf("acl entry %d ", i);
printf("\ta_type = %d ", aclEnt[i].a_type );
printf("\ta_id = %d ", aclEnt[i].a_id );
printf("\ta_perm = %o\n", aclEnt[i].a_perm );
}
/* find out how many ACL entries in the existing ACL on the object */
if (( prevCount = acl(pathname, ACL_CNT, NACLENTRIES, aclEnt)) == -1 ) {
printf("acl(ACL_CNT) error= %d, text = %s\n", errno, strerror(errno));
return 1;
}
/* Allocate space, reserving 1 extra ACL entry for the new GROUP entry */
newCount = prevCount + 1;
if (( aclEnt = (acl_t *) malloc( newCount * sizeof(acl_t))) == 0 ) {
printf("malloc error= %d, text = %s\n", errno, strerror(errno));
return 1;
}
/* sort all of the ACL entries into proper order for acl( ACL_SET) */
Thread stack Private The memory where all thread-local variables are stored
Thread program counter Private The address of the instruction that the thread is about to execute
Thread context Private The data maintained by the threads library on behalf of a thread;
contains the per-thread signal mask, which is used by the
pthread_kill() function
All external data Global Includes process and module global resources
Heap Global
File descriptors and file Global Includes file and record locks
state
Signal mask Global The per-process signal mask, used by the kill() function
Mutex and condition variable initialization attributes: Not defined. A mutex or condition variable can be
_POSIX_THREAD_PROCESS_SHARED operated on only by threads in the same process that
initialized the mutex or condition variable.
Thread scheduling attribute: Not defined. Threads are created with the
_POSIX_THREAD_PRIORITY_SCHEDULING PTHREAD_SCOPE_PROCESSscheduling contention scope
by default. Threads contend directly with other threads
within their process. This attribute cannot be altered.
The scheduling allocation domain size is 1. Threads are
always bound to the same processor as the parent thread.
Thread scheduling attribute: The default value is SCHED_FIFO. This attribute cannot
schedpolicy be altered.
Mutex initialization scheduling attributes: Not defined. The prioceiling and protocol attributes
_POSIX_THREAD_PRIO_INHERIT are not defined.
_POSIX_THREAD_PRIO_PROTECT
Thread creation attribute: Defined. The thread creation stack size attribute can be
_POSIX_THREAD_ATTR_STACKSIZE set in the attribute object.
Thread creation attribute: Not defined. The location of the storage to be used for the
_POSIX_THREAD_ATTR_STACKADDR stack of the created thread cannot be altered.
Signal Handling
There are two basic types of signals:
• Synchronous signals represent events that occur inside a process.
Synchronous signals occur immediately after the instruction that caused the event—for
example, attempting to divide by zero. A synchronous signal is associated with the thread
that is executing when the event occurs. A thread can install signal handlers (using the
sigaction() function) for the synchronous signals that occur during its execution. For
terminating signals, the default behavior is to terminate the process.
• Asynchronous signals represent events external to a process.
A thread can wait for a set of asynchronous signals using the spt_sigwait() function. If
a thread is waiting for a type of signal that is received, the thread is awakened and if a signal
handler has been installed, it is invoked, and the signal is considered handled; otherwise,
the default signal action is taken. For a terminating signal, the default behavior is to terminate
the process. For J-series RVUs, H06.06 and later H-series RVUs, and G06.29 and later G-series
RVUs, you can define signal-catching functions for asynchronous signals. See “Thread-Aware
Signal Handling” (page 265).
API Description
spt_signal() Allows the calling thread to change the action to be taken when a specific signal is
delivered to the thread issuing this function call. To enable thread-aware signal handling,
export the SPT_THREAD_AWARE_SIGNAL environmental variable from within the
shell to the value 1. If thread-aware signal handling is not enabled, signals are handled
at the process level.
For C applications, an application call to signal() is automatically mapped to
spt_signal() when you compile the application using the
#define _SPT_THREAD_SIGNAL feature test macro or an equivalent compiler
command option.
For C++ applications, an application call to signal() is automatically mapped to
spt_signal() when you compile the application using the
#define _SPT_THREAD_SIGNAL_PRAGMA feature test macro or an equivalent
compiler command option.
spt_alarm() Arranges for a SIGALRM signal to be delivered to the process from a thread in the
specified number of seconds. To enable thread-aware signal handling, export the
SPT_THREAD_AWARE_SIGNAL environmental variable from within the shell to the
value 1. If thread-aware signal handling is not enabled, alarms are handled at the
process level.
For C applications, an application call to alarm() is automatically mapped to
spt_alarm() when you compile the application using the
#define _SPT_THREAD_SIGNAL feature test macro or an equivalent compiler
command option.
For C++ applications, an application call to alarm() is automatically mapped to
spt_alarm() when you compile the application using the
#define _SPT_THREAD_SIGNAL_PRAGMA feature test macro or an equivalent
compiler command option.
Limitations
Do not deliver signals like SIGALRM and SIGCHLD using the kill command or the raise()
function because these functions do not provide enough information about the process IDs for
the parent and child processes. Instead, use the spt_alarm() function to raise alarms.
Examples
Example 11-1 (page 268) provides an example of handling the synchronous signal SIGFPE.
The output of Example 11-1 (page 268) depends on whether thread-aware signal handling is
enabled:
• If thread-aware signal handling not enabled, the signal handler defined in the example,
sighand, is not executed, and signal 31 (SIGABEND) is delivered to the process.
• If thread-aware signal handling is enabled, the signal handler defined in the example is
executed, and signal 8 (SIGFPE) is received by the thread. On successful return from a
signal-catching function for a SIGFPE, SIGILL, SIGLIMIT,SIGMEMERR, SIGMEMMGR,
SIGNOMEM, SIGSEGV, or SIGSTK signal that was not generated by a kill() or raise()
function call, a process receives a SIGABEND signal and terminates.
1. The SIGPIPE and SIGURG signals are synchronous for H06.20 and earlier H-series RVUs and J06.09 and earlier J-series
RVUs, and asynchronous for H06.21 and later H-series RVUs and J06.10 and later J-series RVUs.
pthread_t thread1;
int rc;
printf("Enter Testcase - %s\n", argv[0]);
Example 11-2 (page 270) creates a thread that waits for asynchronous signal SIGINT.
Sample input:
> kill -2 process-name
or
<CRTL-C>
Both of these inputs generate a SIGINT signal.
The output of Example 11-2 (page 270) depends on whether thread-aware signal handling is
enabled:
• If thread-aware signal handling is not enabled, the program terminates, which is the default
behavior when signal 2 (SIGINT) is received. Sample output:
sigset_t waitset;
int rc1,rc2;
sigfillset( &waitset );
sigdelset( &waitset,SIGINT);
sigact_t.sa_handler = sighand;
rc1 = sigaction(SIGINT,&sigact_t,NULL);
printf("\nspt_sigaction returned %d\n",rc1);
rc2=sigsuspend(&waitset);
printf("\nspt_sigsuspend returned %d\n",rc2);
return NULL;
pthread_t thread1;
int rc;
printf("Enter Testcase - %s\n", argv[0]);
pthread_create(&thread1, NULL, threadfunc, NULL);
sleep(1);
printf("Wait for threads to complete\n");
pthread_join(thread1, NULL);
printf("Main completed\n");
return 0;
}
Example 11-3 (page 272) demonstrates handling the SIGCHLD signal. This example creates two
threads, each of which call fork(). When the child process executes, the process raises the
SIGCHLD signal.
void sig_cld1(int);
void sig_cld2(int);
void *do_work1(void *arg)
{
pid_t pid;
sigact_t.sa_handler =sig_cld1;
sigact_t.sa_flags = 0;
rc =spt_sigaction(SIGCHLD,&sigact_t,NULL);
printf("\nspt_sigaction for thread1 returned %d\n",rc);
if ((pid = fork()) < 0)
printf("ERROR IN FORK\n");
else if (pid == 0)
{
sleep(2);
printf("\nInside Child of Thread1\n");
exit(0);
}
spt_waitpid(pid,NULL,NULL);
return NULL;
}
}
void main()
{
pthread_t tid1,tid2;
pthread_create(&tid1,NULL,do_work1,NULL);
pthread_create(&tid2,NULL,do_work2,NULL);
sched_yield ();
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
printf ("\nMain Completed\n");
Example 11-4 (page 274) provides an example of SIGALRM handling. It creates two threads that
wait for a SIGALRM signal.
The output of Example 11-4 (page 274) depends on whether thread-aware signal handling is
enabled:
• If thread-aware signal handling not enabled, the entire process terminates when the SIGALRM
signal is received. Sample output:
spt_sigaction for thread1 returned 0
spt_sigaction for thread2 returned 0
• If thread- aware signal handling is enabled, SIGALRM signal is delivered to the correct
thread, and the sighand1() and sighand2() functions define the actions to be taken . Sample
output:
spt_sigaction for thread1 returned 0
spt_sigaction for thread2 returned 0
Signal received for thread1 is 14
spt_sigsuspend for thread1 returned -1
spt_sigwait returned 0
spt_sigwait for thread2 returned for signal 14
Main Completed
/** You must also export the environment variable SPT_THREAD_AWARE_SIGNAL **/
/** to 1 to enable thread-aware signal handling **/
#define SPT_THREAD_AWARE /** enables thread aware behavior and maps **/
/** functions other than alarm() and signal() to their spt_ versions**/
#define SPT_THREAD_SIGNAL /** maps alarm() to spt_alarm()**/
#include <spthread.h>
void sighand1(int);
void sighand2(int);
struct sigaction sigact_t;
int rc;
void *do_work(void *arg)
{
sigset_t set;
sigfillset(&set);
sigdelset(&set,SIGALRM);
sigact_t.sa_handler = sighand1;
rc = spt_sigaction(SIGALRM,&sigact_t,NULL);
printf("\n spt_sigaction for thread1 returned %d\n",rc);
alarm(5);
rc = spt_sigsuspend(&set);
printf("\nspt_sigsuspend for thread1 returned %d\n",rc);
return NULL;
}
sigset_t set;
int sig;
sigemptyset(&set);
sigaddset(&set,SIGALRM);
sigact_t.sa_handler = sighand2;
rc=spt_sigaction(SIGALRM,&sigact_t,NULL);
printf("\nspt_sigaction for thread2 returned %d\n",rc);
alarm(6);
rc=spt_sigwait(&set,&sig);
printf("\nspt_sigwait returned %d\n",rc);
printf("\nspt_sigwait for thread2 returned for signal %d\n",sig);
return NULL;
int main()
{
pthread_t tid1,tid2;
pthread_create(&tid1,NULL,do_work,NULL);
pthread_create(&tid2,NULL,do_work1,NULL);
sched_yield();
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
printf("\nMain Completed\n");
}
{
printf("Signal received for thread1 is %d\n",signo);
}
Threading Considerations
Application designers should be aware of the following general threading considerations when
developing a Standard POSIX Threads application:
• “Sharing Process Resources” (page 276)
• “Using Standard Libraries” (page 276)
• “Addressing the Thread Stack” (page 277)
• “Making Process-Blocking Calls” (page 277)
• “Using Nowait Input or Output” (page 277)
• “Yielding Control” (page 278)
• “Using Signals” (page 278)
• “Spawning a New Process” (page 279)
• “Isolating Faults” (page 279)
No Asynchronous Cancels
Standard POSIX Threads does not support the asynchronous receipt of cancels; a thread can
never exit prematurely from a standard library due to cancellation. Therefore, an application
does not need to protect the run-time state of standard libraries by disabling cancelability before
making a call into the libraries.
Using Signals
• The following signal features are not supported:
— Job Control Signals. The stop a process or continue a process actions implied by these
signals are also not supported.
— The Real-time Signals Extension option.
• Use the sigaction() function, not the signal() function, to specify the action to be
taken when a given signal is received.
• The threads library contains jacket routines for the following OSS system and library
functions:
sigaction()
sigpending()
sigsuspend()
pause()
sleep()
In addition, spt_alarm() and spt_signal() are provided for thread aware signal
handling (see “Thread-Aware Signal Handling” (page 265)).
• The pthread_kill() function provides a mechanism for synchronously directing a signal
to a thread in the calling process.
• A signal is handled in the context of the given thread. However, the signal action (terminating
or stopping) might affect the process as a whole. See “Thread-Aware Signal Handling”
(page 265).
• Signals sent with the pthread_kill() function are queued in FIFO order for the target
thread. More than one instance of the same signal might be pending for a thread. However,
applications should not rely on this ordering.
• You must specify whether a signal listed in Table 11-3 (page 264) as generating a saveabend
actually generates a saveabend by specifying the -Wsaveabend flag in c89 or c99, or
saveabend in nld, ld, or eld.
• If a signal is delivered to a thread waiting on a condition variable, then upon return from
the signal handler, the thread will resume waiting for the condition variable as if it were not
interrupted.
Isolating Faults
Because all threads created by a process share the process address space, there is no address
space protection between the application threads in a process. One application thread can corrupt
data, causing other threads or the entire process to fail.
#include <assert.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <strings.h>
/*
Defines thread-aware functions calls to the threads package:
*/
#define SPT_THREAD_AWARE
#include <spthread.h>
/*
Defines a short macro to convert file descriptors to non-blocking (T1248’s
thread-aware functions are thread-aware only if the file descriptor is non-
blocking):
*/
#define fd_make_nonblock(fd) \
assert(fcntl(fd,F_SETFL,fcntl(fd,F_GETFL)|O_NONBLOCK) != -1)
/*
Defines the port the server will run on:
*/
/*
Shows the worker thread that is created after each accept:
*/
char buffer[1024];
time_t now;
time(&now);
strcpy(buffer, ctime(&now));
send(*(int *)sock_fd, &buffer, strlen(buffer), 0);
close(*(int *)sock_fd);
return NULL;
}
{
int inet_addr_port = SERVER_PORT;
int sock=-1,accept_fd=-1;
size_t size;
struct sockaddr_in servaddr, accept_addr;
/*
Defines one pthread_t per request we intend to handle:
*/
pthread_t my_thread;
pthread_attr_t my_attr;
/*
Turns on concurrency:
*/
/*
Initializes attribute:
*/
if(pthread_attr_init(&my_attr))
{
perror("pthread_attr_init");
exit(-1);
}
/*
Sets detach Attribute:
*/
if(pthread_attr_setdetachstate(&my_attr,PTHREAD_CREATE_DETACHED))
{
perror("pthread_attr_setdetachstate");
exit(-1);
}
/*
Creates socket:
*/
/*
Sets up Bind:
*/
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(inet_addr_port);
{
perror("Bind Error");
exit(-1);
}
fd_make_nonblock(sock);
/*
Sets socket to listen:
*/
if (listen(sock, 1) < 0)
{
perror("Listen Error");
exit(-1);
}
/*
Starts server:
*/
while(1)
{
bzero(&accept_addr, sizeof(accept_addr));
/*
Dispatches a thread to handle service request:
*/
if(pthread_create(&my_thread,&my_attr,&worker_thread,&accept_fd)
{
perror("pthread_create");
exit(-1);
}
} /* while */
}/* main */
Example 11-6 (page 287) also creates a threaded time-of-day server socket, but using $RECEIVE.
#define SPT_THREAD_AWARE
/*
Must come after cextdecs.h:
*/
#include <spthread.h>
time(&now);
strcpy(buffer, ctime(&now));
/*
A compiler warning will occur regarding the next line, which is OK:
*/
int main(void)
{
pthread_t my_thread;
pthread_attr_t my_attr;
char *filename = "$RECEIVE";
char buffer[1024];
long bytesread, error;
short receive_info[17];
short dialog_info;
short target;
short filenum;
/*
Sets concurency level:
*/
if(pthread_setconcurrency(1))
{
perror("pthread_setconcurency");
exit(-1);
}
/*
Initializes attribute:
*/
if(pthread_attr_init(&my_attr))
/*
Sets detach state for thread attribute:
*/
if(pthread_attr_setdetachstate(&my_attr,PTHREAD_CREATE_DETACHED)!=0)
{
perror("pthread_attr_setdetachstate");
exit(-1);
}
while (1)
{
error = spt_RECEIVEREAD(filenum, buffer, (short)sizeof(buffer),
&bytesread, -1, receive_info, &dialog_info);
fprintf(stderr,"main_thread: spt_RECEIVEREAD: error: %d\n",error);
target = receive_info[2];
{
perror("pthread_create");
exit(-1);
}
} /* while */
} /* main */
NOTE: In this section, thread-aware and nonblocking thread-aware functions are listed
explicitly. However, instead of calling these functions directly, HP recommends that you
use preprocessor directives when compiling your application. See “Preprocessor Directives
Automatically Map Standard System Calls to Thread-Aware or Nonblocking Thread-Aware
System Calls” (page 293).
Regular Files
For regular files, the spt_*z() set of functions are thread-aware. The spt_*z() set of functions
block the calling thread but allow the other threads to run, whether or not the file descriptor is
nonblocking. These functions never return the errors EAGAIN, EINPROGRESS, or
EWOULDBLOCK for regular files, so there are no nonblocking thread-aware functions for regular
files.
In contrast, the spt_*() and spt_*x() sets of functions are not thread-aware for regular files.
For regular files, these functions are always process-blocking.
The spt_*z() set of functions are supported on systems running J06.04 and later J-series RVUs
and H06.15 and later H-series RVUs, and are listed in the rightmost column, labeled Thread-Aware
(Regular Files) and Nonblocking Thread-Aware (Non-Regular Files) Functions, of Table 11-6
(page 292).
In addition to the functions listed in Table 11-6 (page 292), these additional functions, athough
not thread-aware, support the use of spt_*z() set of thread-aware functions by serializing file
operations on an open file:
spt_fstat64z()
spt_fstatz()
spt_lseek64z()
spt_lseekz()
spt_*x() Always thead-aware. Can be nonblocking Always process-blocking (all threads in the
for the calling thread. process must wait for I/O to complete)
File descriptor is nonblocking:
— Function is nonblocking thread- aware
(does not block any threads, including
the calling thread): it returns an error
instead of blocking the thread.
File descriptor is not nonblocking:
— Function is thread-aware (other threads
can continue to run)
— Function blocks the calling thread.
1 The functions spt_fstat64z(), spt_fstatz(), spt_lseek64z(), and spt_lseek64z() are not thread
aware but support the spt_*z() thread-aware functions for regular files by serializing file operations on an
open file.
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 389)
Table 11-6 System and Equivalent Thread-Aware Functions
Standard (Process-Blocking) Thread-Aware Functions Nonblocking Thread-Aware Thread-Aware (Regular Files)
OSS Functions (Non-Regular Files Only) Functions (Non-Regular Files and Nonblocking
Only) Thread-Aware (Non-Regular
Files) Functions
— spt_alarm() —
dup2() — spt_dup2x()
fsync() — — spt_fsyncz()
ftruncate() — — spt_ftruncatez()
ftruncate64() — — spt_ftruncate64z()
select() spt_select() —
spt_select_single_np()
sigaction() spt_sigaction() —
— spt_signal() —
sigpending() spt_sigpending() —
sigsuspend() spt_sigsuspend() —
wait() spt_wait() —
sleep() spt_sleep() —
— spt_usleep() —
system() spt_system() —
waitpid() spt_waitpid() —
Preprocessor Directive Behavior for Non-Regular File Behavior for Regular File
Descriptors Descriptors
Example 11-8 (page 297) shows opening a file descriptor for use with a thread-aware function. If
the file descriptor is to be used with a nonblocking thread-aware function, it is not necessary to
set the O_NONBLOCK flag.
Example 11-9 (page 297) shows preparing an open file descriptor for use with a thread-aware
function. If the file descriptor is to be used with a nonblocking thread-aware function, it is not
necessary to set the O_NONBLOCK flag.
Example 11-10 (page 299) is a multithreaded program that performs I/O on multiple OSS regular
files using the nonblocking thread-aware functions and guardian nowaited I/O.
#include <limits.h>
#include <stdlib.h>
/* Use the non-blocking version of the thread aware library */
#define SPT_THREAD_AWARE_NONBLOCK
#include <spthread.h>
#include <tal.h>
#include <cextdecs.h(CANCELREQ, FILE_CLOSE_, FILE_GETINFO_, FILE_OPEN_, \ READX, WRITEX)>
/********************/
/* LITERALS/DEFINES */
/********************/
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
exit(0);
}
/**********************************************/
/* read the OSS file in a thread aware manner */
/**********************************************/
while (1)
{
nbytes = read(fd, iobuf, IOSIZE);
if (nbytes < 0)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
{
/**************************************************************************/
/* NOTE that this code does not execute for regular (disk) files, because */
/* read() on a regular file never returns EWOULDBLOCK or EAGAIN */
/**************************************************************************/
ret = spt_fd_read_ready(fd, NULL);
if (ret != 0)
{
printf("*** ERROR in OSS_read_thread: spt_fd_read_ready()
failed w/err %d\n",ret);
exit(0);
sched_yield();
}
} /* while */
close(fd);
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
close(fd);
/* Grd_READ_thread --
*
* Description:
*
* This thread reads an OSS file using Guardian Nowait I/O.
*
* This function performs Guardian nowait I/O in a thread aware manner,
* such that the entire program never blocks.
* Note however that this thread blocks when it waits for I/O completions.
* Other threads are free to do work while this thread is blocked waiting for
* an I/O completion.
*
* Since Guardian nowait I/O is not serialized, this program can have multiple
* outstanding Guardian I/O requests.
*
* Results:
* none.
*
*------------------------------------------------------------------------
*/
/*************************************************************************/
/* open the OSS file using FILE_OPEN_() so we can do Guardian nowait I/O */
/*************************************************************************/
err = FILE_OPEN_(Grd_READ_file,
(short) sizeof(Grd_READ_file),
&fnum,
0 /* rd_wr */,
0 /* shared */,
1 /* nowait-depth */ ,
/*********************/
/* register the fnum */
/*********************/
spte = spt_regFile(fnum);
if (spte != SPT_SUCCESS)
{
printf("*** ERROR in Grd_READ_thread: spt_regFile() failed w/error %d ***\n",
(int) spte);
exit(0);
}
/***************************************************/
/* Do Guardian nowait I/O in a thread aware manner */
/***************************************************/
while (1)
{
tag = spt_generateTag();
spt_unregFile(fnum);
FILE_CLOSE_(fnum);
/*
/*****************************************************************************/
/* now open the OSS file using FILE_OPEN_() so we can do Guardian nowait I/O */
/*****************************************************************************/
err = FILE_OPEN_(Grd_WRITE_file,
(short) sizeof(Grd_WRITE_file),
&fnum,
0 /* rd_wr */,
0 /* shared */,
1 /* nowait-depth */ ,
0 /* sync depth - NO CHECKPOINTING */,
0x0020 /* options - bit <10> set to open OSS pathname */);
if (err > 0)
{
printf("*** ERROR in Grd_WRITE_thread: FILE_OPEN_() of % failed w/error
%d ***\n", Grd_WRITE_file, (int) err);
exit(0);
}
spt_unregFile(fnum);
FILE_CLOSE_(fnum);
return(NULL);
}
/*************************************/
/* Process command line arguments */
/*************************************/
if (argc > 9)
{
printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>] [-R <OSS-file>] [-W
<OSS-file>]\n");
exit(0);
}
/********************************************************/
/* Set the concurrency level for the thread scheduler */
/********************************************************/
pthread_setconcurrency(CONCURRENCY_LEVEL);
/**********************************/
/* Create all of the I/O threads */
/**********************************/
/************************************************************************/
/* wait for the threads to complete - this is where control is passed */
/* to the threads */
/************************************************************************/
} /* main() */
Example 11-11 (page 309) is a multithreaded program similar to Example 11-10 (page 299) except
that performs I/O on multiple OSS regular files using the thread-aware functions that are available
when you use the define SPT_THREAD_AWARE_XNONBLOCK (available on systems running J06.04
and later J-series RVUs and H06.15 and later H-series RVUs). With these functions, you do not
have to use Guardian functions to allow other threads to continue to work while another thread
waits for I/O to complete on an open file.
#include <limits.h>
#include <stdlib.h>
/* Use the thread-aware library functions that are thread-aware
* (thread-blocking instead of process-blocking) for regular files
*/
#define SPT_THREAD_AWARE_XNONBLOCK
#include <spthread.h>
/********************/
/* LITERALS/DEFINES */
/********************/
/*
*-----------------------------------------------------------------
* OSS_read_thread --
*
* Description:
*
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
exit(0);
}
/**********************************************/
/* read the OSS file in a thread aware manner */
/**********************************************/
while (1)
{
nbytes = read(fd, iobuf, IOSIZE);
if (nbytes < 0)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
{
/**************************************************************************/
/* NOTE that this code does not execute for regular (disk) files, because */
/* read() on a regular file never returns EWOULDBLOCK or EAGAIN */
/**************************************************************************/
ret = spt_fd_read_ready(fd, NULL);
if (ret != 0)
{
printf("*** ERROR in OSS_read_thread: spt_fd_read_ready()
failed w/err %d\n",ret);
exit(0);
}
}
else
{
printf("*** ERROR in OSS_read_thread: read() failed w/error
%d ***\n",errno);
exit(0);
}
}
else if (nbytes == 0) /* EOF */
{
break;
}
else /* read successful */
{
filesize += nbytes;
}
} /* while */
close(fd);
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
close(fd);
/*************************************/
/* Process command line arguments */
/*************************************/
if (argc > 9)
{
printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>]\n");
exit(0);
}
pthread_setconcurrency(CONCURRENCY_LEVEL);
/**********************************/
/* Create all of the I/O threads */
/**********************************/
/************************************************************************/
/* wait for the threads to complete - this is where control is passed */
/* to the threads */
/************************************************************************/
} /* main() */
asctime() asctime_r()
ctermid() ctermid_r()
ctime() ctime_r()
gamma() gamma_r()
getgrent() getgrent_r()
getgrgid() getgrgid_r()
getgrnam() getgrnam_r()
gethostbyaddr() gethostbyaddr_r()
gethostbyname() gethostbyname_r()
gethostent() gethostent_r()
getlogin() getlogin_r()
getnetbyaddr() getnetbyaddr_r()
getnetbyname() getnetbyname_r()
getnetent() getnetent_r()
getprotobyname() getprotobyname_r()
getprotobynumber() getprotobynumber_r()
getprotoent() getprotoent_r()
getpwent() getpwent_r()
getpwnam() getpwnam_r()
getpwuid() getpwuid_r()
getservbyname() getservbyname_r()
getservbyport() getservbyport_r()
getservent() getservent_r()
gmtime() gmtime_r()
lgamma() lgamma_r()
localtime() localtime_r()
rand() rand_r()
readdir() readdir_r()
strtok() strtok_r()
tmpnam() tmpnam_r()
ttyname() ttyname_r()
#include<spthread.h>
#include<stdio.h>
void *gettok(void *args)
{
char str[25] = "a,b,c,";
char str5[25] = "x,y,z,";
char **lasts;
char *str1 = NULL;
char *ptr;
lasts = &str1;
ptr = strtok_r(str,",",lasts);
while(ptr != NULL)
{
printf("\n thread - %d token - %s",args,ptr);
sleep(2);
ptr = strtok_r(NULL,",",lasts);
}
ptr = strtok_r(str5,",",lasts);
while(ptr != NULL)
{
printf("\n thread - %d token - %s",args,ptr);
sleep(2);
ptr = strtok_r(NULL,",",lasts);
}
printf("\n");
}
void main()
{
pthread_t T[2];
int ret_value,t;
for(t=0;t < 2;t++)
{
ret_value = pthread_create(&T[t],NULL,(void *)gettok,(void *)t);
if (ret_value != 0)
{
printf("Error in creating the thread");
exit(1);
}
}
pthread_join(T[0],NULL);
pthread_join(T[1],NULL);
exit(0);
}
spt_unregFile() Unregister the file number as one you will manage. Any threads
waiting on file number I/O will awaken with SPT_ERROR and system
error 16.
spt_regFileIOHandler() Register the file number as one you will manage through a
user-supplied callback. Invoke this callback immediately after each
I/O on filenum completes.
spt_wakeup() Wake up a thread awaiting the tagged I/O on file number. The
awakened thread returns from spt_awaitio() with SPT_SUCCESS.
spt_regFile() Register the file number as one you will manage through the default
callback.
spt_interrupt() Interrupt all threads awaiting I/O on file number. I/O is not cancelled
by this function. Interrupted threads will return from spt_awaitio()
with a return value of SPT_ERROR.
spt_interruptTag() Interrupt the thread awaiting the tagged IO on file number. I/O is not
cancelled by this function. Interrupted threads will return from
spt_awaitio() with a return value of SPT_ERROR.
spt_generateTag() Increment and return a static long appropriate for use as a tag. This
long will eventually wrap and therefore return tags that may still be
in use. For example, if a process calls spt_generateTag() 100 times
every second, the wrap will occur on the 248th day.
Example 11-15 illustrates using a thread-aware read() function. This example assumes you are
using the thread-aware library (spt_*() functions) instead of the nonblocking thread-aware
library (spt_*x() functions) or the thread-aware library for regular files (spt_*z() functions).
If you were to rewrite this example using the nonblocking thread-aware library, you could call
read() and handle the the EWOULBLOCK error instead of checking the O_NONBLOCK flag
of the file descriptor (see Example 11-16 (page 319)).
...
#define SPT_THREAD_AWARE /* maps read() to spt_read() */
#include <spthread.h>
...
ssize_t
my_read(int filedes, void *buffer, size_t nbytes)
{
int before_flags;
Example 11-16 illustrates using a nonblocking thread-aware read() function. This example
assumes you are using the nonblocking thread-aware library (spt_*x() functions) instead of
...
#define SPT_TRHEAD_AWARE_NONBLOCK /* maps read() to spt_readx() */
#include <spthread.h>
...
{
int rv;
while (1)
{
rv = read(filedes, buffer, nbytes);
continue;
}
}
break;
}
return rv;
}
Example 11-17 shows a code fragment that uses the READX() function in a thread-aware manner,
which is appropriate when you are not using the thread-aware library. An alternative to this
approach is to use the SPT_READX() thread-aware function.
tag = spt_generateTag();
cc = READX(filenum, buffer, read_count, , tag);
/* If READX() failed. */
if (_status_lt(cc))
{
short short_error;
/* Loop forever. */
while (1)
{
spte = spt_awaitio(filenum, tag, timelimit, count_read,
&error, NULL);
return error;
Example 11-20 shows a single thread calling the thread-aware spt_RECEIVEREAD() function.
Using thread-aware $RECEIVE functions allows one or more threads to perform work on
$RECEIVE, without a thread unnecessarily blocking another thread.
short filenum;
void *
thread_start(void *parms)
{
long bytesread, error;
char buffer[2];
short receive_info[17];
while (1)
{
error = spt_RECEIVEREAD(filenum, buffer,
(short)sizeof(buffer), &bytesread, -1,
receive_info, NULL);
if (error != 0) break;
// Do real work here!
error = spt_REPLYX("server's reply.", 15, NULL,
receive_info[2], 0);
if (error != 0) break;
}
fprintf(stderr,"thread_start: error: %d\n",error);
return NULL;
}
int
main()
{
pthread_t thread1, thread2;
char *filename = "$RECEIVE";
if (spt_INITRECEIVE(filenum, 2) != 0)
{
fprintf(stderr,"main: spt_INITRECEIVE failed\n");
exit(1);
}
if (pthread_join(thread1, NULL) != 0)
{
perror("main: pthread_join");
exit(1);
}
SPT_READX Returns data from an open file to the application process data area
SPT_READUPDATEX Reads data from a disk or process file in anticipation of a subsequent write to
the file
SPT_READUPDATELOCKX Locks, then reads the record from the current position in the file in anticipation
of a subsequent call to SPT_WRITEUPDATEX or
SPT_WRITEUPDATEUNLOCKX
SPT_WRITEREADX Writes data to a file from an array in the application, then waits for data to be
transferred back from the file
SPT_UNLOCKFILE Unlocks a disk file and any records in that file currently locked by the user
SPT_LOCKREC Excludes other users from accessing a record at the current position
short filenum;
printf("\nHello, I am in Thread1\n");
error = FILE_CLOSE_(filenum);
printf("error in file close %d\n",error);
}
void main()
{
pthread_t T[2];
int ret_value;
int t = 1;
pthread_join(T[0],NULL);
pthread_join(T[1],NULL);
exit(0);
}
spt_regOSSFileIOHandler Register the file descriptor as one that the user will manage through a
user supplied callback.
spt_unregOSSFileIOHandler Unregister file descriptor as one that the user will manage.
Example 11-23 shows an OSS timer callback program flow. As soon as possible, the pthreads
scheduler initially invokes the timer callback, with successive invocations of the callback driven
by the callback’s return value. For more information, see the spt_TimerHandler_p(2) reference
page.
Defines
_PUT_MODEL_
(Required) You must use the _PUT_MODEL_ define when building a threaded application
based on the PUT Model library. Because thread-aware signal handling is always enabled
in the PUT Model library, the alarm() and signal() functions are mapped to the PUT
Model library versions of these functions (similar to what the SPT_THREAD_SIGNAL and
SPT_THREAD_PRAGMA_SIGNAL defines do for the SPT library). For more information
about thread-aware signal handling, see “Thread-Aware Signal Handling” (page 377).
Environment Variables
PUT_THREAD_AWARE_REGULAR_IO_DISABLE
Allows you to disable the thread aware regular file I/O behavior. For more information about
thread-aware regular file I/O behavior, see “Thread-Aware and Nonblocking OSS Functions”
(page 345).
PUT_PROTECTED_STACK_DISABLE
Allows you to disable protected stack support. When you disable protected stack support,
the heap allocation method is used to create the thread stack. For more information about
protected stacks, see “The Protected Thread Stack for Signals” (page 336).
Standards Conformance
The POSIX threads standard is officially described in Institute of Electrical and Electronics
Engineers, Inc., 2004 IEEE Std 1003.1-2001, IEEE Std 1003.1-2001/Cor 1-2002 and IEEE Std
1003.1-2001/Cor 2-2004. For simplicity, this manual refers to the “Standard document.” The
Standard document is available for purchase online at http://standards.ieee.org/.
Portable pthreads functions provided by the PUT Model library (designated with either the
pthread_ or PTHREAD_ prefix and without the _np or _NP suffix) comply with the IEEE Std
1003.1, 2004, POSIX System Application Program Interface.
In contrast to the SPT library, the PUT Model library does not provide these global variables
because these global variables are not specified in the final standard:
pthread_attr_default
pthread_mutexattr_default
pthread_condattr_default
Thread scheduling attribute: schedpolicy The default value is SCHED_FIFO. This attribute cannot
be altered.
Mutex initialization scheduling attributes: Defined as -1. The prioceiling and protocol
_POSIX_THREAD_PRIO_INHERIT attributes are not defined.
_POSIX_THREAD_PRIO_PROTECT
Thread creation attribute: Defined as 0 (zero). The thread creation stack size attribute
_POSIX_THREAD_ATTR_STACKSIZE can be set in the attribute object.
Thread creation attribute: The location of the storage to be used for the stack of the
_POSIX_THREAD_ATTR_STACKADDR created thread cannot be altered. Defined as -1.
Process Resources
All resources of a process—for example, open files or memory—are either global or private, as
shown in Table 12-2. Private resources can be accessed only by a specific thread. Global resources
can be accessed by all threads. Access to global resources by threads should be synchronized
using mutex or condition variables.
Table 12-2 Process Resources
Resource Type Description
Thread stack Private The memory where all thread-local variables are stored
Thread program counter Private The address of the instruction that the thread is about to execute
Thread context Private The data maintained by the threads library on behalf of a thread;
contains the per-thread signal mask, which is used by the
pthread_kill() function
All external data Global Includes process and module global resources
Heap Global
File descriptors and file Global Includes file and record locks
state
Signal mask Private The per-thread signal mask, used by the pthread_kill(),
sigaction(), sigwait(), sigmask(), and sigsuspend()
functions
Signal stack Global The stack that is used to run the signal handler
Using Signals
• The following signal features are not supported:
— Job Control Signals. The stop a process or continue a process actions implied by these
signals are also not supported.
— The Real-time Signals Extension option.
• Use the sigaction() function, not the signal() function, to specify the action to be
taken when a given signal is received.
Limitations
Do not deliver signals like SIGALRM and SIGCHLD using the kill command or the raise()
function because these functions do not provide enough information about the process IDs for
the parent and child processes. Instead, use the PUT Model library version of the alarm()
function to raise alarms.
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include “myio.h” /* contains my_printf which is process blocking */
pthread_t thread1;
my_printf("Enter Testcase - %s\n", argv[0]);
Example 12-2 (page 341) creates a thread that waits for asynchronous signal SIGINT.
Sample input:
> kill -2 process-name
or
sigset_t waitset;
int rc1,rc2;
sigfillset( &waitset );
sigdelset( &waitset,SIGINT);
sigact_t.sa_handler = sighand;
rc1 = sigaction(SIGINT,&sigact_t,NULL);
my_printf("\nsigaction returned %d\n",rc1);
rc2=sigsuspend(&waitset);
my_printf("\nsigsuspend returned %d\n",rc2);
return NULL;
pthread_t thread1;
my_printf("Enter Testcase - %s\n", argv[0]);
pthread_create(&thread1, NULL, threadfunc, NULL);
sleep(1);
my_printf("Wait for threads to complete\n");
pthread_join(thread1, NULL);
my_printf("Main completed\n");
return 0;
}
Example 12-3 (page 342) demonstrates handling the SIGCHLD signal. This example creates two
threads, each of which call fork(). When the child process executes, the process raises the
SIGCHLD signal. The SIGCHLD signal is delivered to the correct thread, and sigaction()
function in the example defines the action to be taken. Sample output:
sigaction for thread1 returned 0
sigaction for thread2 returned 0
Inside Child of Thread2
Signal received for Thread2 is 18
Inside Child of Thread1
Signal received for Thread1 is 18
Main Completed
void sig_cld1(int);
void sig_cld2(int);
void *do_work1(void *arg)
{
pid_t pid;
sigact_t.sa_handler =sig_cld1;
sigact_t.sa_flags = 0;
rc =sigaction(SIGCHLD,&sigact_t,NULL);
my_printf("\nsigaction for thread1 returned %d\n",rc);
if ((pid = fork()) < 0)
my_printf("ERROR IN FORK\n");
else if (pid == 0)
{
sleep(2);
my_printf("\nInside Child of Thread1\n");
exit(0);
}
waitpid(pid,NULL,NULL);
return NULL;
}
}
int main()
{
pthread_t tid1,tid2;
pthread_create(&tid1,NULL,do_work1,NULL);
pthread_create(&tid2,NULL,do_work2,NULL);
sched_yield ();
Example 12-4 (page 344) provides an example of SIGALRM handling. It creates two threads that
wait for a SIGALRM signal. The SIGALRM signal is delivered to the correct thread, and the
sighand1() and sighand2() functions define the actions to be taken. Sample output:
sigaction for thread1 returned 0
sigaction for thread2 returned 0
Signal received for thread1 is 14
sigsuspend for thread1 returned -1
sigwait returned 0
sigwait for thread2 returned for signal 14
Main Completed
void sighand1(int);
void sighand2(int);
struct sigaction sigact_t;
int rc;
void *do_work(void *arg)
{
sigset_t set;
sigfillset(&set);
sigdelset(&set,SIGALRM);
sigact_t.sa_handler = sighand1;
rc = sigaction(SIGALRM,&sigact_t,NULL);
my_printf("\n sigaction for thread1 returned %d\n",rc);
alarm(5);
rc = sigsuspend(&set);
my_printf("\nsigsuspend for thread1 returned %d\n",rc);
return NULL;
}
sigset_t set;
int sig;
sigemptyset(&set);
sigaddset(&set,SIGALRM);
sigact_t.sa_handler = sighand2;
rc=sigaction(SIGALRM,&sigact_t,NULL);
my_printf("\nsigaction for thread2 returned %d\n",rc);
alarm(6);
rc=sigwait(&set,&sig);
my_printf("\nsigwait returned %d\n",rc);
my_printf("\nsigwait for thread2 returned for signal %d\n",sig);
return NULL;
int main()
{
pthread_t tid1,tid2;
pthread_create(&tid1,NULL,do_work,NULL);
pthread_create(&tid2,NULL,do_work1,NULL);
sched_yield();
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
my_printf("\nMain Completed\n");
}
{
my_printf("Signal received for thread1 is %d\n",signo);
}
Regular Files
For regular files, thread-aware functions block the calling thread but allow the other threads to
run, whether or not the file descriptor is nonblocking. These functions never return the errors
EAGAIN, EINPROGRESS, or EWOULDBLOCK for regular files, so there are no nonblocking
thread-aware functions for regular files. Table 12-5 (page 346) lists the functions for which PUT
Model library provides a version that is thread-aware for regular files. You can disable
thread-aware I/O for regular files by setting the
PUT_THREAD_AWARE_REGULAR_IO_DISABLE environment variable before you start the
process.
In addition to the functions listed in Table 12-5 (page 346), these additional functions, although
not thread-aware, support the use of thread-aware functions by serializing file operations on an
open file:
dup2()
fstat64()
fstat()
lseek64()
lseek()
Non-Regular Files
For non-regular files, there are functions that can provide thread-aware behavior or both
nonblocking and thread-aware behavior:
• The set of functions that are thread-aware are thread-aware whether or not the file descriptor
is nonblocking. If the O_NONBLOCK flag is set, these functions are also nonblocking: they
do not block the calling thread or the other threads, and they return one of these errors to
the application: EAGAIN, EINPROGRESS, or EWOULDBLOCK. Otherwise, these functions
block the calling thread but allow other threads to run. These functions remove the need for
the application to explicitly set the O_NONBLOCK flag of the file descriptor to enable
thread-aware behavior. The thread-aware functions are listed in the Nonblocking
Thread-Aware Functions (Non-Regular Files Only) column of Table 12-5 (page 346).
NOTE: To determine which RVUs support an OSS function, see Appendix A (page 389)
Table 12-5 System and Equivalent Thread-Aware Functions
Standard Nonblocking and thread Nonblocking and thread aware Thread aware in PUT Model
(Process-Blocking) OSS aware in PUT Model in PUT Model library for library (functions not related to
Functions library for regular files non-regular files file I/O)
accept() — yes —
alarm() — — yes
connect() — yes —
dup2() — yes —
fork() — — yes
fstat() yes — —
fstat64() yes — —
fsync() yes — —
ftruncate() yes — —
ftruncate64() yes — —
lseek() yes — —
lseek64() yes — —
pause() — — yes
readv() yes — —
recv() — yes —
recvfrom() — yes —
recvmsg() — yes —
select() — yes —
send() — yes —
sendmsg() — yes —
sendto() — yes —
sigaction() — — yes
sigaltstack() — — yes
signal() — — yes
sigpending() — — yes
sigsuspend() — — yes
sigwait() — — yes
sleep() — — yes
usleep() — — yes
wait() — — yes
waitpid() — — yes
writev() — — yes
Example 12-6 (page 348) shows opening a file descriptor for use with a thread-aware function. It
is not necessary to set the O_NONBLOCK flag.
Example 12-7 (page 349) shows preparing an open file descriptor for use with a thread-aware
function. It is not necessary to set the O_NONBLOCK flag.
Example 12-8 (page 350) is a multithreaded program that performs I/O on multiple OSS regular
files using the thread-aware functions that are available when you use the define _PUT_MODEL_.
With these functions, you do not have to use Guardian functions to allow other threads to continue
to work while another thread waits for I/O to complete on an open file.
#define _PUT_MODEL_
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include “myio.h” /* contains my_printf which is process blocking */
/* Use the thread-aware library functions that are thread-aware */
/* (thread-blocking instead of process-blocking) for regular files */
#include <pthread.h>
/********************/
/* LITERALS/DEFINES */
/********************/
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
exit(0);
}
/**********************************************/
/* read the OSS file in a thread aware manner */
/**********************************************/
while (1)
{
nbytes = read(fd, iobuf, IOSIZE);
if (nbytes < 0)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
{
/**************************************************************************/
/* NOTE that this code does not execute for regular (disk) files, because */
/* read() on a regular file never returns EWOULDBLOCK or EAGAIN */
/**************************************************************************/
ret = put_fd_read_ready(fd, NULL);
if (ret != 0)
{
my_printf("*** ERROR in OSS_read_thread: put_fd_read_ready() \
failed w/err %d\n",ret);
exit(0);
}
}
else
{
my_printf("*** ERROR in OSS_read_thread: read() failed w/error \
%d ***\n",errno);
exit(0);
}
}
else if (nbytes == 0) /* EOF */
{
break;
}
else /* read successful */
{
filesize += nbytes;
}
} /* while */
close(fd);
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
/*********************/
/* open the OSS file */
/*********************/
close(fd);
/*************************************/
/* Process command line arguments */
/*************************************/
if (argc > 9)
{
my_printf("Usage: sptdio [-r <OSS-file>] [-w <OSS-file>]\n");
exit(0);
}
/***************************************************/
/* wait for the threads to complete - */
/* this is where control is passed to the threads */
/* to the threads */
/***************************************************/
} /* main() */
Threads Portability
The PUT Model library follows the POSIX Threads Standard document. Using thread functions
whose names end with _np (non-portable) decreases the portability of a program, because these
functions are extensions to the Standard document. Using the jacket routines provided by HP
also reduces portability of a threaded application; see “Jacket Routines (Nonblocking Versions
of SEVERCLASS_ and TMF System Calls)” (page 368) for more information about the jacket
routines.
Thread Safety
The lists in this section apply to systems running J06.10 or later J-series RVUs or H06.21 or later
H-series RVUs only:
• Functions listed in the Open System Services System Calls Reference Manual or in the Open
System Services Library Calls Reference Manual are safe for use in threaded programs unless
they are listed in “Functions That Are Not Thread Safe” (page 357).
• Functions that contain a cancellation point are listed in “Cancellation Points” (page 357).
• Functions that allow a cancellation point to occur are listed in “Potential Cancellation Points”
(page 358).
Cancellation Points
These functions contain a cancellation point:
close()
fcntl() (with F_SETLK as cmd)
fsync()
read()
readv()
sigwait()
write()
writev()
#define _PUT_MODEL_
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include “myio.h” /* contains my_printf which is process blocking */
ptr = strtok_r(str,",",lasts);
while(ptr != NULL)
{
my_printf("\n thread - %d token - %s",args,ptr);
sleep(2);
ptr = strtok_r(NULL,",",lasts);
}
ptr = strtok_r(str5,",",lasts);
while(ptr != NULL)
{
my_printf("\n thread - %d token - %s",args,ptr);
sleep(2);
ptr = strtok_r(NULL,",",lasts);
}
my_printf("\n");
}
int main()
{
pthread_t T[2];
int ret_value,t;
for(t=0;t < 2;t++)
{
ret_value = pthread_create(&T[t],NULL,gettok,(void *)t);
if (ret_value != 0)
{
my_printf("Error in creating the thread");
exit(1);
}
}
pthread_join(T[0],NULL);
pthread_join(T[1],NULL);
exit(0);
}
put_unregFile() Unregister the file number as one you will manage. Any threads
waiting on file number I/O will awaken with put_ERROR and system
error 16.
put_regFileIOHandler() Register the file number as one you will manage through a
user-supplied callback. Invoke this callback immediately after each
I/O on filenum completes.
put_wakeup() Wake up a thread awaiting the tagged I/O on file number. The
awakened thread returns from put_awaitio() with put_SUCCESS.
put_regFile() Register the file number as one you will manage through the default
callback.
put_interrupt() Interrupt all threads awaiting I/O on file number. I/O is not cancelled
by this function. Interrupted threads will return from put_awaitio()
with a return value of put_ERROR.
put_interruptTag() Interrupt the thread awaiting the tagged IO on file number. I/O is not
cancelled by this function. Interrupted threads will return from
put_awaitio() with a return value of put_ERROR.
put_generateTag() Increment and return a static long appropriate for use as a tag. This
long will eventually wrap and therefore return tags that may still be
in use. For example, if a process calls put_generateTag() 100 times
every second, the wrap will occur on the 248th day.
Example 12-12 illustrates using a nonblocking thread-aware read() function. If you were to
disable thread-aware behavior by using the PUT_THREAD_AWARE_REGULAR_IO_DISABLE
environment variable, you risk blocking the whole process if the file descriptor points to a regular
file.
...
#define _PUT_MODEL_ /* maps read() to thread-aware read() */
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
...
{
int rv;
while (1)
{
rv = read(filedes, buffer, nbytes);
continue;
}
}
break;
}
return rv;
}
Example 12-13 shows a code fragment that uses the READX() function in a thread-aware manner,
which is appropriate when you are not using the thread-aware library. An alternative to this
approach is to use the put_READX() thread-aware function.
tag = put_generateTag();
cc = READX(filenum, buffer, read_count, , tag);
/* If READX() failed. */
if (_status_lt(cc))
{
short short_error;
/* Loop forever. */
while (1)
{
spte = put_awaitio(filenum, tag, timelimit, count_read,
&error, NULL);
return error;
Example 12-16 shows a single thread calling the thread-aware put_RECEIVEREAD() function.
Using thread-aware $RECEIVE functions allows one or more threads to perform work on
$RECEIVE, without a thread unnecessarily blocking another thread.
#define _PUT_MODEL_
#include <cextdecs.h(FILE_OPEN_)>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include “myio.h” /* contains my_fprintf which is process blocking */
short filenum;
void *
thread_start(void *parms)
{
long bytesread, error;
char buffer[2];
short receive_info[17];
while (1)
{
error = put_RECEIVEREAD(filenum, buffer,
(short)sizeof(buffer), &bytesread, -1,
receive_info, NULL);
if (error != 0) break;
/* Do real work here! */
error = put_REPLYX("server's reply.", 15, NULL,
receive_info[2], 0);
if (error != 0) break;
}
my_fprintf(stderr,"thread_start: error: %d\n",error);
return NULL;
}
int
main()
{
pthread_t thread1, thread2;
char *filename = "$RECEIVE";
if (put_INITRECEIVE(filenum, 2) != 0)
{
my_fprintf(stderr,"main: put_INITRECEIVE failed\n");
exit(1);
}
if (pthread_join(thread2, NULL) != 0)
{
perror("main: pthread_join");
exit(1);
}
}
Jacket Routines (Nonblocking Versions of SEVERCLASS_ and TMF System Calls) 369
• A process using the TMF transaction jacket routines must not call:
— The TMF procedures BEGINTRANSACTION, ABORTTRANSACTION,
ENDTRANSACTION, or RESUMETRANSACTION
— The SQL/MP BEGIN-WORK and COMMIT-WORK procedures
• A process can perform up to the default of 100 concurrent transactions, with up to 1000
transactions maximum declared using the put_setTMFConcurrentTransaction()
function. If the maximum is exceeded, a call to the
put_setTMFConcurrentTransaction() function fails, returning error number 83 (too
many transactions).
PUT_READX Returns data from an open file to the application process data area
PUT_READUPDATEX Reads data from a disk or process file in anticipation of a subsequent write to
the file
PUT_READUPDATELOCKX Locks, then reads the record from the current position in the file in anticipation
of a subsequent call to PUT_WRITEUPDATEX or
PUT_WRITEUPDATEUNLOCKX
PUT_WRITEREADX Writes data to a file from an array in the application, then waits for data to be
transferred back from the file
PUT_UNLOCKFILE Unlocks a disk file and any records in that file currently locked by the user
PUT_LOCKREC Excludes other users from accessing a record at the current position
short filenum;
my_printf("\nHello, I am in Thread1\n");
error = FILE_CLOSE_(filenum);
my_printf("error in file close %d\n",error);
}
int main()
{
pthread_t T[2];
int ret_value;
int t = 1;
pthread_join(T[0],NULL);
pthread_join(T[1],NULL);
exit(0);
}
put_regOSSFileIOHandler Register the file descriptor as one that the user will manage through a
user supplied callback.
put_unregOSSFileIOHandler Unregister file descriptor as one that the user will manage.
Example 12-19 shows an OSS timer callback program flow. As soon as possible, the pthreads
scheduler initially invokes the timer callback, with successive invocations of the callback driven
by the callback’s return value. For more information, see the put_TimerHandler_p(2) reference
page.
Header Files
You must change the header file in #include statements from spthread.h to pthread.h.
It is important to investigate any warning diagnostics generated when a source text is compiled
after changing an inclusion of spthread.h into an inclusion of pthread.h. For example, a
warning such as function "fcntl" declared implicitly reports that no explicit definition
of fcntl() was declared, therefore the compiler assumed defaults for all function attributes.
Consequently, calls to fcntl() are not mapped to the non-blocking variant of fcntl(). For a
PUT Model application this situation causes an unneeded and unwanted suspension of the entire
process. The remedy in such cases is to include whichever standard header file defines the
function and to ensure that you have also defined the _PUT_MODEL_ macro.
pthread_address_t void *
pthread_addr_t void *
pthread_integer_t int
Global Variables
In contrast to the SPT library, the PUT Model library does not provide these global variables
because these global variables are not specified in the IEEE Standard (1003.1, 2004 edition):
pthread_attr_default
pthread_mutexattr_default
pthread_condattr_default
pthread_mutexattr_getkind_np() pthread_mutexattr_gettype()
pthread_mutexattr_setkind_np() pthread_mutexattr_settype()
pthread_attr_getguardsize_np() pthread_attr_getguardsize()
pthread_attr_setguardsize_np() pthread_attr_setguardsize()
Threading Considerations
Application designers should be aware of the following general threading considerations when
developing a the PUT Model library application:
• “Sharing Process Resources” (page 378)
• “Using Standard Libraries” (page 378)
• “Addressing the Thread Stack” (page 379)
• “Making Process-Blocking Calls” (page 380)
• “Using Nowait Input or Output” (page 380)
• “Yielding Control” (page 380)
• “Using Signals” (page 335)
• “Spawning a New Process” (page 380)
• “Isolating Faults” (page 380)
Yielding Control
Because the PUT Model library are never preempted, a call to the sched_yield() function
might be needed to allow time-critical run-time threads to execute. This function releases the
processor to another thread of the same or higher priority. The calling thread may get control
immediately if no threads of the same or higher priority are ready to run.
Be careful using the sched_yield() function. Misuse causes unnecessary context switching,
which increases overhead without allowing the other threads to execute. For example, it is
counterproductive for a thread to yield control while it has a needed resource locked.
Isolating Faults
Because all threads created by a process share the process address space, there is no address
space protection between the application threads in a process. One application thread can corrupt
data, causing other threads or the entire process to fail.
#define _PUT_MODEL_
#define _XOPEN_SOURCE_EXTENDED 1
#include <assert.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <strings.h>
#include <stdlib.h>
#include <string.h>
/*
Defines thread-aware functions calls to the threads package:
*/
#include <pthread.h>
/*
Defines a short macro to convert file descriptors to non-blocking
(thread-aware functions are thread-aware only if the file descriptor
is non-blocking):
*/
#define fd_make_nonblock(fd) \
assert(fcntl(fd,F_SETFL,fcntl(fd,F_GETFL)|O_NONBLOCK) != -1)
/*
Defines the port the server will run on:
*/
/*
Shows the worker thread that is created after each accept:
*/
char buffer[1024];
time_t now;
time(&now);
strcpy(buffer, ctime(&now));
send(*(int *)sock_fd, &buffer, strlen(buffer), 0);
close(*(int *)sock_fd);
return NULL;
}
{
int inet_addr_port = SERVER_PORT;
int sock=-1,accept_fd=-1;
size_t size;
struct sockaddr_in servaddr, accept_addr;
pthread_t my_thread;
pthread_attr_t my_attr;
/*
Turns on concurrency:
*/
if(pthread_setconcurrency(1))
{
perror("pthread_setconcurrency");
exit(-1);
}
/*
Initializes attribute:
*/
if(pthread_attr_init(&my_attr))
{
perror("pthread_attr_init");
exit(-1);
}
/*
Sets detach Attribute:
*/
if(pthread_attr_setdetachstate(&my_attr,PTHREAD_CREATE_DETACHED))
{
perror("pthread_attr_setdetachstate");
exit(-1);
}
/*
Creates socket:
*/
/*
Sets up Bind:
*/
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(inet_addr_port);
{
perror("Bind Error");
exit(-1);
}
fd_make_nonblock(sock);
if (listen(sock, 1) < 0)
{
perror("Listen Error");
exit(-1);
}
/*
Starts server:
*/
while(1)
{
bzero(&accept_addr, sizeof(accept_addr));
accept_fd = accept(sock, NULL, NULL);
if (accept_fd < 0)
{
perror("Accept Error");
exit(-1);
}
/*
Dispatches a thread to handle service request:
*/
if(pthread_create(&my_thread,&my_attr,&worker_thread,&accept_fd))
{
perror("pthread_create");
exit(-1);
}
} /* while */
}/* main */
Example 12-21 (page 386) also creates a threaded time-of-day server socket, but using $RECEIVE.
#define _PUT_MODEL_
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
#include <cextdecs.h(FILE_OPEN_,READX,FILE_CLOSE_,WRITEX,FILE_GETINFO_)>
#include <cextdecs.h(FILE_GETRECEIVEINFO_)>
#include <cextdecs.h(REPLYX)>
#include <cextdecs.h(READUPDATEX)>
#include “myio.h” /** contains my_printf which is process-blocking**/
/*
Must come after cextdecs.h:
*/
#include <pthread.h>
time(&now);
strcpy(buffer, ctime(&now));
/*
A compiler warning will occur regarding the next line, which is OK:
*/
int main(void)
{
pthread_t my_thread;
pthread_attr_t my_attr;
char *filename = "$RECEIVE";
char buffer[1024];
long bytesread, error;
short receive_info[17];
short dialog_info;
short target;
short filenum;
/*
Sets concurency level:
*/
if(pthread_setconcurrency(1))
{
perror("pthread_setconcurency");
exit(-1);
}
/*
Initializes attribute:
*/
if(pthread_attr_init(&my_attr))
{
perror("pthread_attr_init");
exit(-1);
}
if(pthread_attr_setdetachstate(&my_attr,PTHREAD_CREATE_DETACHED)!=0)
{
perror("pthread_attr_setdetachstate");
exit(-1);
}
while (1)
{
error = put_RECEIVEREAD(filenum, buffer, (short)sizeof(buffer),
&bytesread, -1, receive_info, &dialog_info);
my_fprintf(stderr,"main_thread: put_RECEIVEREAD: error: %d\n",error);
target = receive_info[2];
{
perror("pthread_create");
exit(-1);
}
} /* while */
} /* main */
Library The hard-copy reference page for the function is in the Open System Services
Library Calls Reference Manual.
System The hard-copy reference page for the function is in the Open System Services
System Calls Reference Manual.
Native Only TNS/R, TNS/E The function is restricted to only the TNS/R and TNS/E native environments.
TNS/E The function is restricted to the TNS/E native environment. It is not supported
in the TNS/R native environment.
RVU Notes H06.nn Support for this function was added after the H06.03 RVU, beginning with the
RVU listed. If there is no G-series RVU listed, this function is not supported
on G-series RVUs. If there is no J-series RVU listed, this function is not
supported on J-series RVUs.
G06.nn Support for this function was added after the G06.25 RVU, beginning with the
RVU listed. If there is no H-series RVU listed, this function is not supported
on H-series RVUs. If there is no J-series RVU listed, this function is not
supported on J-series RVUs.
J06.nn Support for this function was added after the J06.03 RVU, beginning with the
RVU listed. If there is no H-series RVU listed, this function is not supported
on H-series RVUs. If there is no G-series RVU listed, this function is not
supported on G-series RVUs.
[blank] Support for this function for H-series RVUs began with the H06.03 RVU.
Support for this function for G-series RVUs began with or before the G06.25
RVU. Support for this function on J-series RVUs began with the J06.03 RVU.
abort() Library
_abs() Library
abs() Library
acos() Library
389
Function Reference HP Native Only RVU Notes
asctime() Library
asin() Library
atan() Library
atan2() Library
atexit() Library
atof() Library
atoi() Library
atol() Library
atoll() Library
bsearch() Library
catclose() Library
catgets() Library
catopen() Library
391
Function Reference HP Native Only RVU Notes
cfgetispeed() Library
cfgetospeed() Library
cfsetispeed() Library
cfsetospeed() Library
chvol() Library
clearerr() Library
closelog() Library
confstr() Library
cos() Library
cosh() Library
creat() System
ctime() Library
393
Function Reference HP Native Only RVU Notes
difftime() Library
div() Library
drand48() Library
ecvt() Library
endpwent() Library
erand48() Library
exec() System
exit() Library
exp() Library
fdopen() Library
395
Function Reference HP Native Only RVU Notes
feof() Library
ferror() Library
fileno() Library
floor() Library
fopen() Library
free() Library
freopen() Library
frexp() Library
397
Function Reference HP Native Only RVU Notes
fsetpos() Library
gamma() Library
getegid() System
geteuid() System
getgid() System
getgroups() System
399
Function Reference HP Native Only RVU Notes
getopt() Library
getpass() Library
getpgrp() System
getpid() System
getppid() System
getuid() System
globfree() Library
gmtime() Library
hcreate() Library
hdestroy() Library
401
Function Reference HP Native Only RVU Notes
hsearch() Library
htonl() Library
htons() Library
hypot() Library
iconv() Library
iconv_close() Library
iconv_open() Library
if_freenameindex() Library
if_indextoname() Library
if_nameindex() Library
if_nametoindex() Library
isalnum() Library
isalpha() Library
isascii() Library
iscntrl() Library
isdigit() Library
isgraph() Library
islower() Library
isprint() Library
ispunct() Library
isspace() Library
isupper() Library
iswalnum() Library
iswalpha() Library
iswcntrl() Library
iswctype() Library
iswdigit() Library
iswgraph() Library
iswlower() Library
iswprint() Library
iswpunct() Library
iswspace() Library
iswupper() Library
iswxdigit() Library
isxdigit() Library
j0() Library
j1() Library
403
Function Reference HP Native Only RVU Notes
jn() Library
jrand48() Library
labs() Library
lcong48() Library
ldexp() Library
ldiv() Library
lfind() Library
lgamma() Library
lldiv() Library
localeconv() Library
localtime() Library
log() Library
log10() Library
longjump() Library
lrand48() Library
lsearch() Library
405
Function Reference HP Native Only RVU Notes
_max() Library
mblen() Library
mbstowcs() Library
mbtowc() Library
memccpy() Library
memchr() Library
memcmp() Library
memcpy() Library
memmove() Library
memset() Library
_min() Library
mktime() Library
modf() Library
mrand48() Library
nice() System
nl_langinfo() Library
nlist() Library
nrand48() Library
ntohl() Library
ntohs() Library
perror() Library
pow() Library
407
Function Reference HP Native Only RVU Notes
409
Function Reference HP Native Only RVU Notes
qsort() Library
rand() Library
random() Library
re_exec() Library
411
Function Reference HP Native Only RVU Notes
readv() System
regcmp() Library
regcomp() Library
regerror() Library
regex() Library
regexec() Library
regfree() Library
remove() Library
rename() System
rewind() Library
rindex() Library
seed48() Library
setbuf() Library
setjmp() Library
setlocale() Library
413
Function Reference HP Native Only RVU Notes
setlogmask() Library
setstate() Library
setuid() System
setvbuf() Library
sigsetjmp() Library
sin() Library
sinh() Library
415
Function Reference HP Native Only RVU Notes
417
Function Reference HP Native Only RVU Notes
419
Function Reference HP Native Only RVU Notes
sqrt() Library
srand() Library
srand48() Library
strcat() Library
strchr() Library
strcmp() Library
strcoll() Library
strcpy() Library
strcspn() Library
strdup() Library
strerror() Library
strfmon() Library
strftime() Library
strlen() Library
strncat() Library
strncmp() Library
strncpy() Library
strpbrk() Library
strptime() Library
strrchr() Library
strspn() Library
strstr() Library
strtod() Library
strtok() Library
421
Function Reference HP Native Only RVU Notes
strtol() Library
strtoll() Library
strtoul() Library
strtoull() Library
strxfrm() Library
swab() Library
tan() Library
tanh() Library
tdelete() Library
telldir() Library
tempnam() Library
tfind() Library
time() Library
tmpfile() Library
tmpnam() Library
tmpnam_guardian() Library
tmpnam_oss() Library
toascii() Library
_tolower() Library
tolower() Library
_toupper() Library
toupper() Library
towlower() Library
towupper() Library
tsearch() Library
twalk() Library
tzset() Library
423
Function Reference HP Native Only RVU Notes
umask() System
ungetc() Library
ungetwc() Library
usleep() Library
va_arg() Library
va_end() Library
va_start() Library
valloc() Library
vsprintf() Library
wcscat() Library
wcschr() Library
wcscmp() Library
wcscoll() Library
wcscpy() Library
wcscspn() Library
wcsftime() Library
wcslen() Library
wcsncat() Library
wcsncmp() Library
wcsncpy() Library
wcspbrk() Library
wcsrchr() Library
wcsspn() Library
wcstod() Library
wcstok() Library
wcstol() Library
wcstoll() Library
wcstombs() Library
wcstoul() Library
wcstoull() Library
wcswcs() Library
wcswidth() Library
wcsxfrm() Library
wctomb() Library
wctype() Library
wcwidth() Library
wordexp() Library
wordfree() Library
y0() Library
425
Function Reference HP Native Only RVU Notes
y1() Library
yn() Library
G and O Notation
In the columns headed “Module Compiled As,” and “Process Called From,” the letter “G”
indicates “Guardian” and “O” indicates “OSS.”
Specified By
The “Specified By” column indicates where a function or macro is defined:
ISO
The function or macro is specified in the ISO/ANSI C standard.
POSIX
The function or macro is specified in the POSIX.1 or POSIX.2 standard. (Functions identified
as “ISO” are also specified in the POSIX.1 standard.)
HP
The function or macro is an extension specified by HP.
X/OPEN
The function or macro is specified in the XPG4 version 2 specification, which is the basis for
the X/OPEN UNIX brand.
XPG4
The function or macro is specified in the XPG4 specification. (Functions and macros identified
as “ISO” or “POSIX” are also specified in the XPG4 specification.)
Functions and macros specified in the ISO standard are declared for both Guardian and OSS
modules.
By default, functions and macros specified in POSIX, XPG4, and X/OPEN UNIX are declared
only for OSS modules. To use such a function or macro in a Guardian module (if that is allowed),
specify the _XOPEN_SOURCE feature-test macro when you compile the module.
By default, functions and macros specified by HP are declared only for Guardian modules. To
use such a function or macro in an OSS module (if that is allowed), specify the _TANDEM_SOURCE
feature-test macro when you compile the module.
Regardless of whether the function or macro is being called from a Guardian or OSS module,
some functions and macros specified by X/OPEN UNIX require that the
_XOPEN_SOURCE_EXTENDED feature-test macro be specified when you compile the module,
and some require that either the _XOPEN_SOURCE_EXTENDED or the _TANDEM_SOURCE
feature-test macro be specified when you compile the module.
For the most complete information about any function, see the reference page for that function
either online or in the Open System Services System Calls Reference Manual.
Usage Notes
The “Usage Notes” column provides information about the behavior of the function or macro.
Unless indicated otherwise in the “Usage Notes” column, a function or macro has the same
behavior regardless of the module or process environment from which it is called.
Checking variants If the CHECK pragma is specified, functions and macros in both Guardian and OSS
modules perform identical parameter validation. If the NOCHECK pragma is
specified, functions and macros in both Guardian and OSS modules do not perform
extra parameter validation. The Guardian environment compiler defaults to CHECK.
The OSS environment compiler defaults to NOCHECK. Refer to the CHECK pragma
in the C/C++ Programmer’s Guide for details.
Exception variants The function or macro in a Guardian module generates an exception on an arithmetic
fault. The function or macro in an OSS module does not generate an exception on
an arithmetic fault.
Guardian function operates The Guardian function or macro operates only on Guardian objects.
only on Guardian objects
Guardian objects only The function or macro operates only on Guardian objects.
Guardian parameters only The function or macro requires Guardian parameters (Guardian filename, stream
pointer, file descriptor, or process identifier).
Limited OSS objects only The function or macro operates on some types of OSS objects. The extent of support
for OSS objects differs for each function or macro.
Limited when called from The function or macro’s operation is limited when it is called from a Guardian
Guardian process process.
Only Guardian modules or only The function or macro can be called only from a Guardian module within a Guardian
OSS modules process or from an OSS module within an OSS process. The function or macro
cannot be called from both Guardian and OSS modules within the same process.
The module and process environments must be the same. Behavior might be different
in each environment.
OSS function operates on OSS The OSS function or macro operates on OSS objects and some types of Guardian
objects and limited Guardian objects. The extent of support for Guardian objects differs for each function or macro.
objects
OSS function operates only on The OSS function or macro operates only on OSS objects.
OSS objects
OSS objects and limited The function or macro operates on OSS objects and some types of Guardian objects.
Guardian objects The extent of support for Guardian objects differs for each function or macro.
OSS objects only The function or macro operates only on OSS objects.
OSS parameters only The function or macro requires OSS parameters (OSS pathname, stream pointer,
file descriptor, or process identifier).
Parameters must match module When called from a Guardian module, the function or macro requires Guardian
parameters. When called from an OSS module, the function or macro requires OSS
parameters.If the function or macro operates on an open file, the file must have
been opened in a module of the same environment.
Examples
The following examples illustrate how to use Table B-1 (page 431) to determine how functions
and macros can be used in Guardian and OSS programs.
_ _ns_backup_fopen() HP G G
_ HP G G
_ns_fget_file_open_state()
_ _ns_fget_file_state() HP G G
_ _ns_fopen_special() HP G G
_ _ns_fset_file_state() HP G G
_ _ns_start_backup() HP G G
_abs() HP G, O G, O
_is_system_trap() HP G G
_max() HP G, O G, O
_min() HP G, O G, O
_tolower() XPG4 G, O G, O
_toupper() XPG4 G, O G, O
abort() ISO G, O G, O
abs() ISO G, O G, O
asctime() ISO G, O G, O
assert() ISO G, O G, O
atan() ISO G, O G, O
atexit() ISO G, O G, O
atof() ISO G, O G, O
atoi() ISO G, O G, O
atol() ISO G, O G, O
bsearch() ISO G, O G, O
ceil() ISO G, O G, O
cfgetispeed() POSIX O O
cfgetospeed() POSIX O O
cfsetispeed() POSIX O O
cfsetospeed() POSIX O O
chroot() XPG4 G, O G, O
chvol() HP G G
clock() ISO G, O G, O
closelog() X/OPEN G, O G, O
confstr() XPG4 G, O G, O
cos() ISO G, O G, O
ctime() ISO G, O G, O
dec_to_longlong() HP G, O G, O
difftime() ISO G, O G, O
div() ISO G, O G, O
drand48() XPG4 G, O G, O
ecvt() HP G, O G, O
erand48() XPG4 G, O G, O
erf() XPG4 G, O G, O
erfc() XPG4 G, O G, O
exit() ISO G, O G, O
fabs() ISO G, O G, O
fcloseall() HP G G
fgetwc() XPG4 O G, O
fgetws() XPG4 O G, O
floor() ISO G, O G, O
fmod() ISO G, O G, O
fnmatch() POSIX G, O G, O
fopen_std_file() HP G G
fputwc() XPG4 O G, O
fputws() XPG4 O G, O
frexp() ISO G, O G, O
fsync() XPG4 G, O G, O
gamma() XPG4 G, O G, O
get_assign_msg() HP G G
get_assign_msg_by_name() HP G G
get_max_assign_msg HP G G
_ordinal()
get_param_by_name() HP G G
get_param_msg() HP G G
get_startup_msg() HP G G
getcwd() POSIX G, O G, O
getegid() POSIX G, O G, O
getenv() ISO G, O G, O
geteuid() POSIX G, O G, O
getgid() POSIX G, O G, O
getgroups() POSIX O O
getlogin() POSIX O O
getopt() XPG4 O O
getpwnam() POSIX O O
getpwuid() POSIX O O
getsid() XPG4 O O
getuid() POSIX G, O G, O
getwc() XPG4 O G, O
getwchar() XPG4 O O
getws() XPG4 O O
glob() POSIX G, O G, O
globfree() POSIX G, O G, O
gmtime() ISO G, O G, O
hcreate() XPG4 G, O G, O
hdestroy() XPG4 G, O G, O
heap_check() HP G, O G, O
heap_check_always() HP G, O G, O
heap_min_block_size() HP G, O G, O
hsearch() XPG4 G, O G, O
hypot() XPG4 G, O G, O
iconv() XPG4 O O
iconv_close() XPG4 O O
iconv_open() XPG4 O O
ioctl() X/OPEN G, O G, O
isalnum() ISO G, O G, O
isalpha() ISO G, O G, O
isascii() XPG4 G, O G, O
iscntrl() ISO G, O G, O
iscsym() HP G, O G, O
iscsymf() HP G, O G, O
isdigit() ISO G, O G, O
isgraph() ISO G, O G, O
islower() ISO G, O G, O
isnan() ISO G, O G, O
isprint() ISO G, O G, O
ispunct() ISO G, O G, O
isspace() ISO G, O G, O
isupper() ISO G, O G, O
iswalnum() XPG4 G, O G, O
iswalpha() XPG4 G, O G, O
iswcntrl() XPG4 G, O G, O
iswctype() XPG4 G, O G, O
iswdigit() XPG4 G, O G, O
iswgraph() XPG4 G, O G, O
iswlower() XPG4 G, O G, O
iswprint() XPG4 G, O G, O
iswpunct() XPG4 G, O G, O
iswspace() XPG4 G, O G, O
iswupper() XPG4 G, O G, O
iswxdigit() XPG4 G, O G, O
isxdigit() XPG4 G, O G, O
j0() XPG4 G, O G, O
j1() XPG4 G, O G, O
jn() XPG4 G, O G, O
jrand48() XPG4 G, O G, O
labs() ISO G, O G, O
lcong48() XPG4 G, O G, O
ldiv() ISO G, O G, O
lfind() XPG4 G, O G, O
lgamma() XPG4 G, O G, O
localeconv() ISO G, O G, O
localtime() ISO G, O G, O
longlong_to_dec() HP G, O G, O
lrand48() XPG4 G, O G, O
lsearch() XPG4 G, O G, O
mblen() ISO G, O G, O
mbstowcs() ISO G, O G, O
mbtowc() ISO G, O G, O
memccpy() ISO O G, O
mktime() ISO G, O G, O
modf() ISO G, O G, O
mrand48() XPG4 G, O G, O
nl_langinfo() XPG4 G, O G, O
nlist() X/OPEN G, O G, O
nrand48() XPG4 G, O G, O
offsetof() ISO G, O G, O
perror() ISO G, O G, O
putenv() XPG4 O G, O
putw() XPG4 O G, O
putwc() XPG4 O G, O
putwchar() XPG4 O O
putws() XPG4 O O
qsort() ISO G, O G, O
rand() ISO G, O G, O
regcomp() XPG4 O O
regerror() XPG4 O O
regexec() XPG4 O O
regfree() XPG4 O O
reply() HP G G, O
seed48() XPG4 G, O G, O
semctl() XPG4 O O
semget() XPG4 O O
semop() XPG4 O O
setgid() POSIX G, O G, O
setlocale() ISO G, O G, O
setlogmask() X/OPEN G, O G, O
setuid() POSIX G, O G, O
shmat() XPG4 O O
shmctl() XPG4 O O
shmdt() XPG4 O O
shmget() XPG4 O O
sin() ISO G, O G, O
sprintf() ISO G, O G, O
srand() ISO G, O G, O
srand48() XPG4 G, O G, O
sscanf() ISO G, O G, O
strcoll() ISO G, O G, O
strerror() ISO G, O G, O
strfmon() XPG4 G, O G, O
strftime() ISO G, O G, O
strptime() XPG4 G, O G, O
strxfrm() ISO G, O G, O
stscmp() HP G, O G, O
swab() XPG4 G, O G, O
sysconf() POSIX G, O G, O
syslog() X/OPEN G, O G, O
tan() ISO G, O G, O
tanh() ISO G, O G, O
tcdrain() POSIX O O
tcflow() POSIX O O
tcflush() POSIX O O
tcgetattr() POSIX O O
tcgetpgrp() POSIX O O
tcsendbreak() POSIX O O
tcsetattr() POSIX O O
tcsetpgrp() POSIX O O
tdelete() XPG4 G, O G, O
tempnam() XPG4 G, O O
terminate_program() HP G, O G, O
tfind() XPG4 G, O G, O
time() ISO G, O G, O
times() POSIX G, O G, O
toascii() XPG4 G, O G, O
tolower() ISO G, O G, O
toupper() ISO G, O G, O
towlower() XPG4 G, O G, O
towupper() XPG4 G, O G, O
trap_overflows() HP G G
tsearch() XPG4 G, O G, O
ttyname() XPG4 O G, O
twalk() XPG4 G, O G, O
tzset() XPG4 G, O G, O
ulimit() XPG4 G, O G, O
umask() POSIX G, O G, O
uname() POSIX G, O G, O
ungetwc() XPG4 O G, O
va_arg() ISO G, O G, O
va_end() ISO G, O G, O
va_start() ISO G, O G, O
vfscanf() ISO G, O G, O
vscanf() ISO G, O G, O
vsprintf() ISO G, O G, O
vsscanf() ISO G, O G, O
wcscat() XPG4 G, O G, O
wcschr() XPG4 G, O G, O
wcscmp() XPG4 G, O G, O
wcscoll() XPG4 G, O G, O
wcscpy() XPG4 G, O G, O
wcscspn() XPG4 G, O G, O
wcsftime() XPG4 G, O G, O
wcslen() XPG4 G, O G, O
wcsncat() XPG4 G, O G, O
wcsncmp() XPG4 G, O G, O
wcsncpy() XPG4 G, O G, O
wcspbrk() XPG4 G, O G, O
wcsrchr() XPG4 G, O G, O
wcsspn() XPG4 G, O G, O
wcstod() XPG4 G, O G, O
wcstok() XPG4 G, O G, O
wcstol() XPG4 G, O G, O
wcstoll() XPG4 G, O G, O
wcstombs() XPG4 G, O G, O
wcstoul() XPG4 G, O G, O
wcstoull() XPG4 G, O G, O
wcswcs() XPG4 G, O G, O
wcswidth() XPG4 G, O G, O
wcsxfrm() XPG4 G, O G, O
wctomb() XPG4 G, O G, O
wctype() XPG4 G, O G, O
wcwidth() XPG4 G, O G, O
wordexp() POSIX G, O G, O
wordfree() POSIX G, O G, O
y0() XPG4 G, O G, O
y1() XPG4 G, O G, O
yn() XPG4 G, O G, O
Internationalization Functions
In Guardian processes, regardless of whether modules are compiled to run in the Guardian or
OSS environment, only the C/POSIX locale is available. In OSS processes, full internationalization
support is available if the required locales are purchased and installed on the system.
G and O Notation
In the columns headed “Module Compiled As,” and “Process Called From,” the letter “G”
indicates “Guardian” and “O” indicates “OSS.”
Specified By
The “Specified By” column indicates where a function or macro is defined:
FC-MI
The function is specified in the Fibre Channel - Methodologies for Interconnects (FC-MI)
Revision 1.6 Annexure A by the Storage Network Industry Association (SNIA).
ISO
The function or macro is specified in the ISO/ANSI C standard.
POSIX
The function or macro is specified in the POSIX.1 or POSIX.2 standard. (Functions identified
as “ISO” are also specified in the POSIX.1 standard.)
HP
The function or macro is an extension specified by HP.
Threads
The function is part of the Standard POSIX Threads and is specified in the International
Standard ISO/IEC 9945-1; 1996 (E) IEEE Std 1003.1,1996 (Incorporating ANSI/IEEE Stds
1003.1-1990, 1003.1b-1993, 1003.1c-1995, and 1003.1i-1995), or
The function is part of the POSIX User Thread Model and is specified in the IEEE Std 1003.1,
2004.
X/OPEN
The function or macro is specified in the XPG4 version 2 specification, which is the basis for
the X/OPEN UNIX brand.
XLFS
The function or macro is an HP extension to the XPG4 specification based on the Adding
Support for Arbitrary File Sizes to the Single Unix Specification, X/Open Large File Summit (LFS)
submission, version 1.5 (March 20, 1996). This function or macro is supported on systems
running G06.29 or later G-series RVUs or H06.06 or later H-series RVUs.
XPG4
The function or macro is specified in the XPG4 specification. (Functions and macros identified
as “ISO” or “POSIX” are also specified in the XPG4 specification.)
Functions and macros specified in the ISO standard are declared for both Guardian and OSS
modules.
By default, functions and macros specified in POSIX, XPG4, and X/OPEN UNIX are declared
only for OSS modules. To use such a function or macro in a Guardian module (if that is allowed),
specify the _XOPEN_SOURCE feature-test macro when you compile the module.
By default, functions and macros specified by HP are declared only for Guardian modules. To
use such a function or macro in an OSS module (if that is allowed), specify the _TANDEM_SOURCE
feature-test macro when you compile the module.
Usage Notes
The “Usage Notes” column provides information about the behavior of the function or macro.
Unless indicated otherwise in the “Usage Notes” column, a function or macro has the same
behavior regardless of the module or process environment from which it is called.
The following table describes the “Usage Notes” values that appear frequently.
Guardian function operates only on Guardian objects The Guardian function or macro operates only on
Guardian objects.
Guardian objects only The function or macro operates only on Guardian objects.
Limited OSS objects only The function or macro operates on some types of OSS
objects. The extent of support for OSS objects differs for
each function or macro.
Limited when called from Guardian process The function or macro’s operation is limited when it is
called from a Guardian process.
Only Guardian modules or only OSS modules The function or macro can be called only from a Guardian
module within a Guardian process or from an OSS module
within an OSS process. The function or macro cannot be
called from both Guardian and OSS modules within the
same process. The module and process environments
must be the same. Behavior might be different in each
environment.
OSS function operates on OSS objects and limited The OSS function or macro operates on OSS objects and
Guardian objects some types of Guardian objects. The extent of support for
Guardian objects differs for each function or macro.
OSS objects and limited Guardian objects The function or macro operates on OSS objects and some
types of Guardian objects. The extent of support for
Guardian objects differs for each function or macro.
OSS objects only The function or macro operates only on OSS objects.
OSS parameters only The function or macro requires OSS parameters (OSS
pathname, stream pointer, file descriptor, or process
identifier).
Parameters must match module When called from a Guardian module, the function or
macro requires Guardian parameters. When called from
an OSS module, the function or macro requires OSS
parameters.
If the function or macro operates on an open file, the file
must have been opened in a module of the same
environment.
Parameters must match process When called from a Guardian process, the function or
macro requires Guardian parameters. When called from
an OSS process, the function or macro requires OSS
parameters.
If the function or macro operates on an open file, the file
must have been opened in a module of the same
environment.
Examples
The following examples illustrate how to use Table C-1 (page 457) to determine how functions
and macros can be used in Guardian and OSS programs.
1. The following information can be derived about the edfseek() function:
• Is an extension specified by HP.
• Can be called only from a Guardian module.
• Can be called from Guardian and OSS processes.
• Requires Guardian parameters.
• Operates only on Guardian objects.
• Because it is specified by HP, it requires the _TANDEM_SOURCE feature-test macro.
2. The following information can be derived about the free() function:
• Specified in the ISO/ANSI C standard.
• Can be called from Guardian and OSS modules.
• Can be called from Guardian and OSS processes.
3. The following information can be derived about the rename() function:
• Specified in the ISO/ANSI C standard.
• Can be called from Guardian and OSS modules.
• Can be called from Guardian and OSS processes.
• Guardian function operates only on Guardian objects; OSS function operates on OSS
objects and limited Guardian objects.
a64l() XPG4 G, O G, O
abort() ISO G, O G, O
_abs() HP G, O G, O
abs() ISO G, O G, O
acos() ISO G, O G, O
acosf() ISO G, O G, O
acosh() ISO G, O G, O
acoshf() ISO G, O G, O
acoshl() ISO G, O G, O
acosl() ISO G, O G, O
asctime() ISO G, O G, O
asin() ISO G, O G, O
asinf() ISO G, O G, O
asinh() ISO G, O G, O
asinhf() ISO G, O G, O
asinhl() ISO G, O G, O
asinl() ISO G, O G, O
assert() ISO G, O G, O
atan() ISO G, O G, O
atanf() ISO G, O G, O
atanh() ISO G, O G, O
atanhf() ISO G, O G, O
atanhl() ISO G, O G, O
atanl() ISO G, O G, O
atan2() ISO G, O G, O
atan2f() ISO G, O G, O
atan2l() ISO G, O G, O
atexit() ISO G, O G, O
atof() ISO G, O G, O
atoi() ISO G, O G, O
atol() ISO G, O G, O
atoll() ISO G, O G, O
basename() POSIX O O
bcmp() XPG4 G, O G, O
bcopy() XPG4 G, O G, O
bsearch() ISO G, O G, O
btowc() ISO G, O G, O
bzero() XPG4 G, O G, O
calloc() ISO G, O G, O
cbrt() XPG4 G, O G, O
cbrtf() ISO G, O G, O
cbrtl() ISO G, O G, O
ceil() ISO G, O G, O
ceilf() ISO G, O G, O
ceill() ISO G, O G, O
cfgetispeed() POSIX G, O G, O
cfgetospeed() POSIX G, O G, O
cfsetispeed() POSIX G, O G, O
cfsetospeed() POSIX G, O G, O
chroot() XPG4 G, O G, O
chvol() HP G G, O
clearerr() ISO G, O G, O
clock() ISO G, O G, O
closelog() X/OPEN G, O G, O
confstr() XPG4 G, O G, O
copysign() ISO G, O G, O
copysignf() ISO G, O G, O
copysignl() ISO G, O G, O
cos() ISO G, O G, O
cosf() ISO G, O G, O
cosh() ISO G, O G, O
coshf() ISO G, O G, O
coshl() ISO G, O G, O
cosl() ISO G, O G, O
crypt() XPG4 G, O G, O
csqrt() ISO G, O G, O
csqrtf() ISO G, O G, O
csqrtl() ISO G, O G, O
ctime() ISO G, O G, O
cuserid() XPG4 G, O G, O
dbm_clearerr() XPG4 O O
dbm_close() XPG4 O O
dbm_delete() XPG4 O O
dbm_error() XPG4 O O
dbm_fetch() XPG4 O O
dbm_firstkey() XPG4 O O
dbm_nextkey() XPG4 O O
dbm_open() XPG4 O O
dbm_store XPG4 O O
dec_to_longlong() HP G, O G, O
difftime() ISO G, O G, O
dirname() POSIX O O
div() ISO G, O G, O
dlclose() HP G, O G, O
dlerror() HP G, O G, O
dlopen() HP G, O G, O
dlresultcode() HP G, O G, O
dlsym() HP G, O G, O
drand48() XPG4 G, O G, O
encrypt() XPG4 G, O G, O
endgrent() POSIX G, O G, O
endhostent() XPG4 O O
endnetent() XPG4 O O
endprotoent() XPG4 O O
endservent() XPG4 O O
erand48() XPG4 G, O G, O
erf() XPG4 G, O G, O
erfc() XPG4 G, O G, O
erfcf() ISO G, O G, O
erfcl() ISO G, O G, O
erff() ISO G, O G, O
erfl() ISO G, O G, O
exit() ISO G, O G, O
exp() ISO G, O G, O
expf() ISO G, O G, O
expl() ISO G, O G, O
expml() XPG4 G, O G, O
expmlf() ISO G, O G, O
expmll() ISO G, O G, O
fabs() ISO G, O G, O
fabsf() ISO G, O G, O
fabsl() ISO G, O G, O
fclose() ISO G, O G, O
fcvt() XPG4 G, O G, O
feof() ISO G, O G, O
ferror() ISO G, O G, O
fflush() ISO G, O G, O
ffs() XPG4 G, O G, O
fgetc() ISO G, O G, O
fgetpos() ISO G, O G, O
fgets() ISO G, O G, O
fgetwc() XPG4 G, O G, O
fgetws() XPG4 G, O G, O
finite() XPG4 G, O G, O
flockfile() Threads G, O G, O
floor() ISO G, O G, O
floorf() ISO G, O G, O
floorl() ISO G, O G, O
fmod() ISO G, O G, O
fmodf() ISO G, O G, O
fmodl() ISO G, O G, O
fmtmsg() XPG4 O O
fnmatch() POSIX O O
fopen_std_file() HP G G
fprintf() ISO G, O G, O
fputc() ISO G, O G, O
fputs() ISO G, O G, O
fputwc() XPG4 G, O G, O
fputws() XPG4 G, O G, O
fread() ISO G, O G, O
free() ISO G, O G, O
freeaddrinfo() XPG4 O O
freehostent() XPG4 O O
frexp() ISO G, O G, O
frexpf() ISO G, O G, O
frexpl() ISO G, O G, O
fscanf() ISO G, O G, O
fseek() ISO G, O G, O
fsetpos() ISO G, O G, O
ftell() ISO G, O G, O
ftime() XPG4 G, O G, O
ftrylockfile() Threads G, O G, O
funlockfile() Threads G, O G, O
fwide() ISO G, O G, O
fwprintf() ISO G, O G, O
fwrite() ISO G, O G, O
fwscanf() ISO G, O G, O
gai_strerror() XPG4 O O
gamma() XPG4 G, O G, O
gcvt() XPG4 G, O G, O
get_assign_msg() HP G G
get_assign_msg_by_name() HP G G
get_max_assign_msg _ordinal() HP G G
get_param_by_name() HP G G
get_param_msg() HP G G
get_startup_msg() HP G G
getaddrinfo() XPG4 O O
getc() ISO G, O G, O
getc_unlocked() Threads G, O G, O
getchar() ISO G, O G, O
getchar_unlocked() Threads G, O G, O
getcwd() POSIX G, O G, O
getdate() XPG4 G, O G, O
getdtablesize() XPG4 O O
getegid() POSIX O O
getenv() ISO G, O G, O
getenv_r() HP G, O G, O
geteuid() POSIX O O
getgid() POSIX O O
getgroups() POSIX O O
gethostbyaddr() XPG4 O O
gethostbyname() XPG4 O O
gethostbyname2() HP O O
gethostent() XPG4 O O
gethostid() XPG4 O O
gethostname() XPG4 O O
getipnodebyaddr() HP O O
getipnodebyname() HP O O
getlogin() POSIX O O
getnameinfo() XPG4 O O
getnetbyaddr() XPG4 O O
getnetbyname() XPG4 O O
getnetbyname_r() HP O O _SPT_MODEL_
getnetent() XPG4 O O
getnetent_r() HP O O _SPT_MODEL_
getopt() XPG4 G, O G, O
getpagesize() ISO O O
getpass() XPG4 O O
getprotobyname() XPG4 O O
getprotobyname_r() HP O O _SPT_MODEL_
getprotobynumber() XPG4 O O
getprotobynumber_r() HP O O _SPT_MODEL_
getprotoent() XPG4 O O
getprotoent_r() HP O O _SPT_MODEL_
getpwent_r() HP G, O G, O _SPT_MODEL_
getpwnam() POSIX G, O G, O
getpwuid() POSIX G, O G, O
gets() ISO G, O G, O
getservbyname() XPG4 O O
getservbyname_r() HP O O _SPT_MODEL_
getservbyport() XPG4 O O
getservbyport_r() HP O O _SPT_MODEL_
getservent() XPG4 O O
getservent_r() HP O O _SPT_MODEL_
getsid() XPG4 O O
getsubopt() XPG4 O O
gettimeofday() XPG4 O O
getuid() POSIX O O
getwc() XPG4 G, O G, O
getwchar() XPG4 G, O G, O
getws() XPG4 G, O G, O
glob() POSIX G, O G, O
globfree() POSIX G, O G, O
gmtime() ISO G, O G, O
HBA_CloseAdapter() FC-MI O O
HBA_FreeLibrary() FC-MI O O
HBA_GetAdapterAttributes() FC-MI O O
HBA_GetAdapterName() FC-MI O O
HBA_GetAdapterPortAttributes() FC-MI O O
HBA_GetDiscoveredPortAttributes() FC-MI O O
HBA_GetFcpTargetMapping() FC-MI O O
HBA_GetNumberOfAdapters() FC-MI O O
HBA_GetPortStatistics() FC-MI O O
HBA_GetVersion() FC-MI O O
HBA_LoadLibrary() FC-MI O O
HBA_OpenAdapter() FC-MI O O
HBA_RefreshInformation() FC-MI O O
hcreate() XPG4 G, O G, O
hdestroy() XPG4 G, O G, O
heap_check() HP G, O G, O
heap_check_always() HP G, O G, O
heap_min_block_size() HP G, O G, O
hsearch() XPG4 G, O G, O
htonl() XPG4 O O
htons() XPG4 O O
hypot() XPG4 G, O G, O
hypotf() ISO G, O G, O
hypotl() ISO G, O G, O
iconv() XPG4 O O
iconv_close() XPG4 O O
iconv_open() XPG4 O O
if_freenameindex() XPG4 O O
if_indextoname() XPG4 O O
if_nameindex() XPG4 O O
if_nametoindex() XPG4 O O
ilogb() XPG4 G, O G, O
ilogbf() ISO G, O G, O
ilogbl() ISO G, O G, O
imaxabs() ISO G, O G, O
imaxdiv() ISO G, O G, O
index() XPG4 G, O G, O
inet_addr() XPG4 O O
inet_lnaof() XPG4 O O
inet_makeaddr() XPG4 O O
inet_netof() XPG4 O O
inet_network() XPG4 O O
inet_ntoa() XPG4 O O
inet_ntop() XPG4 O O
inet_pton() XPG4 O O
initgroups() XPG4 O O
initstate() XPG4 G, O G, O
insque() XPG4 O O
ioctl() X/OPEN G, O G, O
isalnum() ISO G, O G, O
isalpha() ISO G, O G, O
isascii() XPG4 G, O G, O
isblank() ISO G, O G, O
iscntrl() ISO G, O G, O
isdigit() ISO G, O G, O
isgraph() ISO G, O G, O
islower() ISO G, O G, O
isprint() ISO G, O G, O
ispunct() ISO G, O G, O
isspace() ISO G, O G, O
isupper() ISO G, O G, O
iswalnum() XPG4 G, O G, O
iswalpha() XPG4 G, O G, O
iswblank() ISO G, O G, O
iswcntrl() XPG4 G, O G, O
iswctype() XPG4 G, O G, O
iswdigit() XPG4 G, O G, O
iswgraph() XPG4 G, O G, O
iswlower() XPG4 G, O G, O
iswprint() XPG4 G, O G, O
iswpunct() XPG4 G, O G, O
iswspace() XPG4 G, O G, O
iswupper() XPG4 G, O G, O
iswxdigit() XPG4 G, O G, O
isxdigit() XPG4 G, O G, O
j0() XPG4 G, O G, O
j1() XPG4 G, O G, O
jn() XPG4 G, O G, O
jrand48() XPG4 G, O G, O
l64a() XPG4 G, O G, O
labs() ISO G, O G, O
lcong48() XPG4 G, O G, O
ldexp() ISO G, O G, O
ldexpf() ISO G, O G, O
ldexpl() ISO G, O G, O
ldiv() ISO G, O G, O
lfind() XPG4 G, O G, O
lgamma() XPG4 G, O G, O
lgammaf() ISO G, O G, O
lgammal() ISO G, O G, O
llabs() ISO G, O G, O
lldiv() XPG4 G, O G, O
localeconv() ISO G, O G, O
localtime() ISO G, O G, O
log() ISO G, O G, O
logb() XPG4 G, O G, O
logbf() ISO G, O G, O
logbl() ISO G, O G, O
logf() ISO G, O G, O
logl() ISO G, O G, O
loglp() XPG4 G, O G, O
loglpf() ISO G, O G, O
loglpl() ISO G, O G, O
log10() ISO G, O G, O
log10f() ISO G, O G, O
log10l() ISO G, O G, O
longjmp() ISO G, O G, O
longlong_to_dec() HP G, O G, O
lrand48() XPG4 G, O G, O
lsearch() XPG4 G, O G, O
lwres_freeaddrinfo() HP O O
lwres_freehostent() HP O O
lwres_gai_strerror() HP O O
lwres_getaddrinfo() HP O O
lwres_gethostbyaddr() HP O O
lwres_gethostbyname() HP O O
lwres_gethostbyname2() HP O O
lwres_getipnodebyaddr() HP O O
lwres_getipnodebyname() HP O O
lwres_getnameinfo() HP O O
lwres_hstrerror() HP O O
malloc() ISO G, O G, O
_max() HP G, O G, O
mblen() ISO G, O G, O
mbrlen() ISO G, O G, O
mbrtowc() ISO G, O G, O
mbsinit() ISO G, O G, O
mbsrtowcs() ISO G, O G, O
mbstowcs() ISO G, O G, O
mbtowc() ISO G, O G, O
memccpy() ISO G, O G, O
memchr() ISO G, O G, O
memcmp() ISO G, O G, O
memcpy() ISO G, O G, O
memmove() ISO G, O G, O
memset() ISO G, O G, O
_min() HP G, O G, O
mkstemp() XPG4 O O
mktemp() XPG4 O O
mktime() ISO G, O G, O
modf() ISO G, O G, O
modff() ISO G, O G, O
modfl() ISO G, O G, O
mrand48() XPG4 G, O G, O
nextafter() XPG4 G, O G, O
nextafterf() ISO G, O G, O
nextafterl() ISO G, O G, O
nl_langinfo() XPG4 G, O G, O
nlist() HP G, O G, O
nrand48() XPG4 G, O G, O
ntohl() XPG4 O O
ntohs() XPG4 O O
perror() ISO G, O G, O
pow() ISO G, O G, O
powf() ISO G, O G, O
powl() ISO G, O G, O
printf() ISO G, O G, O
putc() ISO G, O G, O
putc_unlocked() Threads G, O G, O
putchar() ISO G, O G, O
putchar_unlocked() Threads G, O G, O
putenv() XPG4 G, O G, O
puts() ISO G, O G, O
putw() XPG4 G, O G, O
putwc() XPG4 G, O G, O
putwchar() XPG4 G, O G, O
putws() XPG4 G, O G, O
qsort() ISO G, O G, O
raise() ISO G, O G, O
rand() ISO G, O G, O
random() XPG4 G, O G, O
realloc() ISO G, O G, O
realpath() O O
regcomp() XPG4 G, O G, O
regerror() XPG4 G, O G, O
regexec() XPG4 G, O G, O
regfree() XPG4 G, O G, O
remainder() XPG4 G, O G, O
remainderf() ISO G, O G, O
remainderl() ISO G, O G, O
remque() XPG4 G, O G, O
rewind() ISO G, O G, O
rindex() XPG4 G, O G, O
rint() XPG4 G, O G, O
rintf() ISO G, O G, O
rintl() ISO G, O G, O
scalb() XPG4 G, O G, O
scanf() ISO G, O G, O
seed48() XPG4 G, O G, O
semctl() XPG4 O O
semget() XPG4 O O
semop() XPG4 O O
setbuf() ISO G, O G, O
setegid() XPG4 O O
seteuid() XPG4 O O
setgid() POSIX O O
setgrent() POSIX G, O G, O
setgroups() HP O O
sethostent() XPG4 O O
setjmp() ISO G, O G, O
setlocale() ISO G, O G, O
setlogmask() X/OPEN O O
setnetent() XPG4 O O
setprotoent() XPG4 O O
setservent() XPG4 O O
setstate() XPG4 G, O G, O
setuid() POSIX O O
setvbuf() ISO G, O G, O
shmat() XPG4 O O
shmctl() XPG4 O O
shmdt() XPG4 O O
shmget() XPG4 O O
shutdown() XPG4 O O
sigaddset() POSIX O O
sigdelset() POSIX O O
sigemptyset() POSIX O O
sigfillset() POSIX O O
sigismember() POSIX O O
siglongjmp() POSIX G, O G, O
sigprocmask() POSIX G, O G, O
sigsetjmp() POSIX G, O G, O
sin() ISO G, O G, O
sinf() ISO G, O G, O
sinh() ISO G, O G, O
sinhf() ISO G, O G, O
sinhl() ISO G, O G, O
sinl() ISO G, O G, O
sockatmark() HP O O
snprintf() ISO G, O G, O
sprintf() ISO G, O G, O
sqrt() XPG4 G, O G, O
sqrtf() ISO G, O G, O
sqrtl() ISO G, O G, O
srand() ISO G, O G, O
srand48() XPG4 G, O G, O
srandom() XPG4 G, O G, O
sscanf() ISO G, O G, O
step() XPG4 G, O G, O
strcasecmp() XPG4 G, O G, O
strcat() ISO G, O G, O
strchr() ISO G, O G, O
strcmp() ISO G, O G, O
strcoll() ISO G, O G, O
strcpy() ISO G, O G, O
strcspn() ISO G, O G, O
strerror() ISO G, O G, O
strerror_r() Threads G, O G, O
strfmon() XPG4 G, O G, O
strftime() ISO G, O G, O
strlen() ISO G, O G, O
strncasecmp() XPG4 G, O G, O
strncat() ISO G, O G, O
strncmp() ISO G, O G, O
strncpy() ISO G, O G, O
strpbrk() ISO G, O G, O
strptime() XPG4 G, O G, O
strrchr() ISO G, O G, O
strspn() ISO G, O G, O
strstr() ISO G, O G, O
strtod() ISO G, O G, O
strtof() ISO G, O G, O
strtoimax() ISO G, O G, O
strtok() ISO G, O G, O
strtol() ISO G, O G, O
strtoll() ISO G, O G, O
strtoul() ISO G, O G, O
strtoull() ISO G, O G, O
strtoumax() ISO G, O G, O
strxfrm() ISO G, O G, O
swab() XPG4 G, O G, O
swprintf() ISO G, O G, O
swscanf() ISO G, O G, O
sysconf() POSIX G, O G, O
syslog() X/OPEN G, O G, O
tan() ISO G, O G, O
tanf() ISO G, O G, O
tanh() ISO G, O G, O
tanhf() ISO G, O G, O
tanhl() ISO G, O G, O
tanl() ISO G, O G, O
tcdrain() POSIX O O
tcflow() POSIX O O
tcflush() POSIX O O
tcgetattr() POSIX O O
tcgetpgrp() POSIX O O
tcsendbreak() POSIX O O
tcsetattr() POSIX O O
tcsetpgrp() POSIX O O
tdelete() XPG4 G, O G, O
tempnam() XPG4 O O
terminate_program() HP G, O G, O
tfind() XPG4 G, O G, O
time() ISO G, O G, O
times() POSIX G, O G, O
toascii() XPG4 G, O G, O
_tolower() XPG4 G, O G, O
tolower() ISO G, O G, O
_toupper() XPG4 G, O G, O
toupper() ISO G, O G, O
towctrans() ISO G, O G, O
towlower() XPG4 G, O G, O
towupper() XPG4 G, O G, O
tsearch() XPG4 G, O G, O
ttyname() XPG4 O G, O
twalk() XPG4 G, O G, O
tzset() XPG4 G, O G, O
ulimit() XPG4 O O
umask() POSIX O O
uname() POSIX O O
ungetc() ISO G, O G, O
ungetwc() XPG4 G, O G, O
unordered() XPG4 G, O G, O
va_arg() ISO G, O G, O
va_end() ISO G, O G, O
va_start() ISO G, O G, O
valloc() XPG4 G, O G, O
vfprintf() ISO G, O G, O
vfscanf() ISO G, O G, O
vfwprintf() ISO G, O G, O
vfwscanf() ISO G, O G, O
vprintf() ISO G, O G, O
vscanf() ISO G, O G, O
vsnprintf() ISO G, O G, O
vsprintf() ISO G, O G, O
vsscanf() ISO G, O G, O
vswprintf() ISO G, O G, O
vswscanf() ISO G, O G, O
vwprintf() ISO G, O G, O
vwscanf() ISO G, O G, O
wcrtomb() ISO G, O G, O
wcscat() XPG4 G, O G, O
wcschr() XPG4 G, O G, O
wcscmp() XPG4 G, O G, O
wcscoll() XPG4 G, O G, O
wcscpy() XPG4 G, O G, O
wcscspn() XPG4 G, O G, O
wcsftime() XPG4 G, O G, O
wcslen() XPG4 G, O G, O
wcsncat() XPG4 G, O G, O
wcsncmp() XPG4 G, O G, O
wcsncpy() XPG4 G, O G, O
wcspbrk() XPG4 G, O G, O
wcsrchr() XPG4 G, O G, O
wcsrtombs() ISO G, O G, O
wcsspn() XPG4 G, O G, O
wcstod() XPG4 G, O G, O
wcstof() ISO G, O G, O
wcstoimax() ISO G, O G, O
wcstok() XPG4 G, O G, O
wcstol() XPG4 G, O G, O
wcstoll() XPG4 G, O G, O
wcstombs() XPG4 G, O G, O
wcstoul() XPG4 G, O G, O
wcstoull() XPG4 G, O G, O
wcstoumax() ISO G, O G, O
wcswcs() XPG4 G, O G, O
wcswidth() XPG4 G, O G, O
wcsxfrm() XPG4 G, O G, O
wctob() ISO G, O G, O
wctomb() XPG4 G, O G, O
wctrans() ISO G, O G, O
wctype() XPG4 G, O G, O
wcwidth() XPG4 G, O G, O
wmemchr() ISO G, O G, O
wmemcmp() ISO G, O G, O
wmemcpy() ISO G, O G, O
wmemmove() ISO G, O G, O
wmemset() ISO G, O G, O
wordexp() POSIX O O
wordfree() POSIX O O
wprintf() ISO G, O G, O
wscanf() ISO G, O G, O
y0() XPG4 G, O G, O
y1() XPG4 G, O G, O
yn() XPG4 G, O G, O
515
HP NonStop system, a demon runs in the OSS environment and has an OSS process ID. See
also static server.
directory A type of OSS file that contains directory entries, which name links to other files. No two
directory entries in the same directory have the same name.
directory tree A hierarchy of directories. In the OSS environment, directories are connected to each other in
a branching hierarchical fashion such that there is only one path between any two directories
(provided there is no backtracking).
dynamic window A window, or virtual terminal, that Telserv creates when it receives a connection request.
EDIT file An unstructured file with the file code 101 in the Guardian file system. An EDIT file can be
processed by either the EDIT or PS Text Edit (TEDIT) editor. An EDIT file typically contains
source program or script code, documentation, or program output. OSS functions can open an
EDIT file only for reading.
EMS See Event Management Service (EMS).
errno An external variable that contains the most recent error condition set by a C function.
event A significant change in some condition in the system or network. An event can be an operational
error, notification of limits exceeded, request for action, notification of lines and other objects
becoming available, and so on. Note that an event is not always an error.
Event A part of the Distributed Systems Management (DSM) product used to provide event collection,
Management event logging, and event distribution facilities. It provides for different event descriptions for
Service (EMS) interactive and programmatic interfaces, lets an operator or application select specific
event-message data, and allows for flexible distribution of event messages within a system or
network.
extended data An area of virtual memory used to contain data.
segment
feature test macro A symbol that, if defined in a program’s source code, includes specific other symbols from a
header within that program’s source code and makes those symbols visible.
FIFO A type of file that is always read and written in a first-in, first-out manner.
file An object to which data can be written or from which data can be read. A file has attributes
such as access permissions and a file type. In the OSS environment, file types include regular
file, character special file, FIFO, pipe, socket, symbolic link, Guardian file, and directory..
file descriptor The nonnegative integer that uniquely identifies a single open of a file to a running process.
Each file descriptor is associated with an open file description that contains data about the file.
file identifier In the Guardian environment, the portion of a filename following the subvolume name. In the
OSS environment, a portion of the internal information used to identify a file in the OSS file
system. The two identifiers are not comparable.
file permission Information about a file that is used, along with other information, to determine whether a
bits process or user has read, write, or execute/search permission to that file. The bits are divided
into three parts: owner, group, and other. Each part is used with the corresponding file class
of processes.
file system In the OSS environment, a collection of files and file attributes. A file system provides the
namespace for the file serial numbers that uniquely identify its files. Open System Services
provides a file system (see also ISO/IEC IS 9945-1: 1990 [ANSI/IEEE Std. 1003.1-1990], Clause
2.2.2.38); the Guardian application program interface (API) provides a file system; and OSS
Network File System (NFS) provides a file system. (OSS NFS filenames and pathnames are
governed by slightly different rules than OSS filenames and pathnames.) Within the OSS and
OSS NFS file systems, filesets exist as manageable objects.
On an HP NonStop system, the Guardian file system for a node is a subset of the OSS virtual
file system. Traditionally, the API for file access in the Guardian environment is referred to as
the Guardian file system.
In some UNIX and NFS implementations, the term file system is used to mean the same thing
as fileset. That is, a file system is a logical grouping of files that, except for the root of the file
system, can be contained only by directories within the file system.
See also fileset.
516 Glossary
filename In the OSS environment, a component of a pathname containing any valid characters other
than a slash (/) or a null. In the Guardian environment, a filename is the set of node name,
volume name, subvolume name, and file identifier characters that uniquely identifies a file.
fileset In the OSS environment, a set of files with a common mount point within the file hierarchy. A
fileset can be part or all of a single virtual file system.
On an HP NonStop system, the Guardian file system for a node has a mount point and is a
subset of the OSS virtual file system. The entire Guardian file system therefore could be viewed
as a single fileset. However, each volume, and each process of subtype 30, within the Guardian
file system is actually a separate fileset.
The term file system is often used interchangeably with fileset in UNIX documentation.
flat segment A type of logical segment. Each flat segment has its own distinct address range within the
process address space that never overlaps the range of any other allocated segments. Thus all
allocated flat segments for a process are always available for use concurrently. Contrast with
selectable segment.
function An OSS or Guardian C function.
group ID The nonnegative integer used to identify a group of users of an HP NonStop network node.
Each user of that node is a member of at least one group. When the identity of a group is
associated with a process, a group ID value is referred to as one of the following:
• Real group ID
• Effective group ID
• Supplementary group ID
• Saved-set group ID
Guardian An environment available for interactive or programmatic use with the HP NonStop operating
system. Processes that run in the Guardian environment use the Guardian system procedure
calls as their application program interface; interactive users of the Guardian environment use
the HP Tandem Advanced Command Language (TACL) or another HP product’s command
interpreter. Contrast with Open System Services (OSS).
Guardian module A module compiled to execute in the Guardian environment.
header An object that, when specified for inclusion in a program’s source code, causes the program to
behave as if the statement including the header were actually a specific set of other programming
statements. A header contains coded information that provides details (such as data item length)
about the data that the header precedes.
In an OSS program, a header is the name of a file known to the run-time library used by a
process. In a Guardian environment C language program, a header is the file identifier for a
file known to the run-time library used by a process.
HP NonStop The product name for the OSS environment. See Open System Services (OSS).
Open System
Services (OSS)
interoperability 1. Within an Expand node, the ability to use the features or facilities of one environment from
another. For example, the gtacl command in the Open System Services (OSS) environment
allows an interactive user to start and use a Guardian tool in the Guardian environment.
2. Among systems from multiple vendors or with multiple versions of operating systems from
the same vendor, the ability to exchange status, files, and other information. Product externals
and end-user publications for NonStop servers often use the term connectivity in this context.
labeled tape A tape containing information about the contents of the tape that prevent undesired overwriting
of the tape.
large file aware An application or function that can process large OSS files in addition to small OSS files. For
example, it must be able to access large files as input and generate large files as output. Contrast
with large file safe.
large file safe An application or function that causes no loss of data or corruption of data when it encounters
a large OSS file. A large file safe application or function is not required to process large OSS
files with the same ability as when it processes small files, but it must handle errors or warnings
detected during file manipulation operations and fail gracefully. Contrast with large file aware.
517
large OSS file A regular file that has a size greater than or equal to approximately 2 gigabytes. Contrast with
small OSS file.
man page A term sometimes used in UNIX documentation for the online or hard-copy version of a file
that provides reference information. See reference page.
nesting The inclusion of items of one type within items of that type. For example, in the OSS
environment, directories can contain directories.
non-regular file An OSS file that is not a regular (disk) file.
noncanonical A terminal input mode in which data is made available to a process when a timer expires or
input mode when a certain number of characters have been entered. Noncanonical data is not grouped into
logical lines of input. This mode is sometimes called block mode or transparent mode. Contrast
with canonical input mode.
nowait I/O The ability of an application process to continue executing in parallel with read or write
operations that it initiates. Contrast with waited I/O.
Object Code A program optimization tool that processes a TNS object file and produces an accelerated file
Accelerator for a TNS/E system. OCA augments a TNS object file with equivalent Intel Itanium instructions.
(OCA) TNS object code that is accelerated runs faster on TNS/E systems than TNS object code that is
not accelerated. Contrast with Accelerator.
OCA See Object Code Accelerator (OCA).
odd-unstructured Files that have no built-in record structures and permit reading and writing of both even and
files odd byte counts and positioning to both even and odd byte addresses.
Open System An open system environment available for interactive or programmatic use with the HP NonStop
Services (OSS) operating system. Processes that run in the OSS environment usually use the OSS application
program interface; interactive users of the OSS environment usually use the OSS shell for their
command interpreter. Synonymous with Open System Services (OSS) environment. Contrast
with Guardian.
operator message A message, intended for an operator, that describes a significant event on an HP NonStop
server.
OSS See Open System Services (OSS).
OSS module A module compiled to execute in the OSS environment.
OSS process ID The unique identifier that represents a process during the lifetime of the process and during
(PID) the lifetime of the process group of that process. See also PID
parent process The process that created a given process, or (if the creating process has stopped) a process that
has inherited a given process.
See also child process.
pathname In the OSS environment, the string of characters that uniquely identifies a file within its file
system. A pathname can be either relative or absolute. See also ISO/IEC IS 9945-1:1990
(ANSI/IEEE Std. 1003.1-1990 or POSIX.1), Clause 2.2.2.57.
persistent process A process that must always be either waiting, ready, or executing. Persistent processes are
usually controlled by a monitor process that checks on the status of persistent processes and
restarts them, if necessary.
PID In the OSS environment, the OSS process ID, a numeric identifier assigned to an OSS process
and unique within an HP NonStop node. In the Guardian environment, PID is sometimes used
to mean either of the following:
• A Guardian process identifier such as the process ID
• The cpu, pin value that is unique to a process within a NonStop node
See also OSS process ID (PID).
pipe An unnamed FIFO, created programmatically by invoking the pipe() function or interactively
with the shell pipe syntax character (|). A shell pipe redirects the standard output of one process
to become the standard input of another process. A programmatic pipe is an interprocess
communication mechanism.
518 Glossary
portable An application that can execute on a wide range of hardware systems from multiple
application manufacturers. A portable application is a program that can be moved with little or no change
in its source code from another manufacturer’s system to an HP NonStop system.
procedure A Guardian system procedure.
process 1. A program that has been submitted to the operating system for execution, or a program that
is currently running in the computer.
2. An address space, a single thread of control that executes within that address space, and the
system resources required by that thread of control.
process group A set of processes that can signal associated processes. Each process in a node is a member of
a process group; the process group has a process group ID. A new process becomes a member
of the process group of its creator.
process handle An identifier that uniquely identifies an OSS or Guardian process within a network of HP
NonStop systems.
reentrant function A function that does not hold static data over successive calls and does not return a pointer to
static data. All data is provided by the caller of the function.
reference page The OSS or Distributed Computing Environment (DCE) online or hard-copy version of a file
that provides reference information for a software facility. Some UNIX documentation uses the
term man page instead, referring either to the online delivery mechanism used to display the
file (usually the shell man command) or to the nature of the file as part of a manual.
regular file In the OSS file system, a file that is a randomly accessible sequence of bytes. A regular file
contains binary or text data and has no structure imposed by the system. Contrast with special
file.
relative pathname A pathname that does not begin with a slash (/) character. A relative pathname is resolved
beginning with the current working directory. Contrast with absolute pathname.
root See root fileset and root directory. See also super ID.
root directory A directory associated with a process that the system uses for pathname resolution when a
pathname begins with a slash (/) character.
root fileset The fileset with the device number of 0, normally containing the root directory for the OSS file
system in an HP NonStop system. HP recommends that this fileset be named “root”.
selectable A type of logical segment formerly known as an extended data segment. The data area for a
segment selectable segment always begins with relative segment 4, and this area can be dynamically
switched among several selectable segments by calls to the Guardian SEGMENT_USE_
procedure. The effect is similar to a rapid overlaying of one large data area.
See also flat segment.
semaphore A mechanism used to provide multiple processes with access to a shared data object.
session A set of process groups associated for job control purposes. A session can have a controlling
terminal.
shared memory An interprocess communication mechanism that allows two or more processes to share a given
region of memory.
shell 1. A program that interprets sequences of text input as commands. A shell can operate on an
input stream or it can interactively prompt and read commands from a terminal.
2. An envelope of code that provides a convenient way to call a procedure in another execution
environment.
signal The method by which an environment notifies a process of an event. Signals are used to notify
a process when an error that is not related to input or output has occurred.
signal delivery The time when OSS takes the action appropriate for a specific process and a specific signal.
signal generation The time when an event occurs that causes a signal for a process.
signal handler A function or procedure that is executed when a specific signal is delivered to a specific process.
signal mask The set of signals that are currently blocked from delivery to a specific process.
small OSS file A regular file that is smaller than approximately 2 gigabytes. Contrast with large OSS file.
socket An end-point for stream-oriented communication. A socket has a file descriptor.
519
special file A file associated with an I/O device. Often called a device file. Special files are read and written
the same as ordinary files, but requests to read or write result in activation of the associated
device. Due to convention and consistency, these files should always reside in the /dev directory.
See also file.
static server In the Guardian environment, a process that runs continuously and provides a specific service
to other processes. A static server differs from a traditional UNIX demon in that a demon
actively looks for tasks to perform, while a static server performs only tasks brought to its
attention by a client (requestor) process.
See also demon.
static window A window, or virtual terminal, that is opened with the Subsystem Control Facility (SCF). You
do not need to establish a Telserv connection before opening a static window.
super ID On HP NonStop systems, a privileged user who can read, write, execute, and purge all files on
the system. The super ID is usually a member of a system-supervisor group.
The super ID has the set of special permissions called appropriate privileges. In the Guardian
environment, the structured view of the super ID, which is (255, 255), is most commonly used;
in the OSS environment, the scalar view of the super ID, which is 65535, is most commonly
used.
terminal A type of OSS character special file that conforms to the interface description in Clause 7 of
ISO/IEC IS 9945-1: 1990.
TNS Refers to fault-tolerant HP computers that support the HP NonStop operating system and that
are based on microcoded complex instruction-set computing (CISC) technology. TNS processors
run the TNS instruction set. Contrast with TNS/R and TNS/E.
TNS object code The TNS instructions that result from processing program source code with a TNS language
compiler. TNS object code executes on TNS, TNS/R, and TNS/E systems.
TNS object file An object file created by a TNS compiler or the Binder. A TNS object file contains TNS
instructions. TNS object files can be processed by the Accelerator or by the TNS Object Code
Accelerator (OCA) to produce to produce accelerated object files. A TNS object file can be run
on TNS, TNS/R, and TNS/E systems.
TNS process A process whose main program object file is a TNS object file, compiled using a TNS compiler.
A TNS process executes in interpreted or accelerated mode while within itself, when calling a
user library, or when calling into TNS system libraries. A TNS process temporarily executes in
native mode when calling into native-compiled parts of the system library. Object files within
a TNS process might be accelerated or not, with automatic switching between accelerated and
interpreted modes on calls and returns between those parts.
Contrast with TNS/R native process and TNS/E native process.
TNS/E Refers to fault-tolerant HP computers that support the HP NonStop operating system and are
based on the Intel Itanium processor. TNS/E systems run the Itanium instruction set and can
run TNS object files by interpretation or after acceleration. TNS/E systems include all HP
NonStop systems that use NSE-x processors. Contrast with TNS and TNS/R.
TNS/E native The Intel Itanium instructions that result from processing program source code with a TNS/E
object code native compiler. TNS/E native object code executes only on TNS/E systems, not on TNS or
TNS/R systems.
TNS/E native An object file created by a TNS/E native compiler that contains Intel Itanium instructions and
object file other information needed to construct the code spaces and the initial data for a TNS/E native
process.
TNS/E native A process initiated by executing a TNS/E native object file. Contrast withTNS process and
process TNS/E native process.
TNS/R Refers to fault-tolerant HP computers that support the HP NonStop operating system and are
based on 32-bit reduced instruction-set computing (RISC) technology. TNS/R systems run the
MIPS-1 RISC instruction set and can run TNS object files by interpretation or after acceleration.
TNS/R systems include all HP systems that use NSR-x processors. Contrast with TNS and
TNS/E.
520 Glossary
TNS/R native The RISC instructions that result from processing program source code with a TNS/R native
object code compiler. TNS/R native object code executes only on TNS/R systems, not on TNS or TNS/E
systems.
TNS/R native An object file created by a TNS/R native compiler that contains RISC instructions and other
object file information needed to construct the code spaces and the initial data for a TNS/R native process.
TNS/R native A process initiated by executing a TNS/R native object file. Contrast with TNS process and
process TNS/E native process.
UID A nonnegative integer that uniquely identifies a user within a node.
The UID is a scalar number consisting of the group number multiplied by 256 and added to
the member number; for example, the UID of the super ID is (255*256) + 255, or 65535. The UID
is used in the OSS environment for functions normally associated with a UNIX user ID.
See also user ID.
unstructured file A disk file that is essentially a large byte array, most often used as a code file or an EDIT file,
not as a data file.
user ID The unique identification of a user within a node.
In the Guardian environment, the term “user ID” usually means the group number and member
number pair; for example, the user ID of the super ID is usually described as (255, 255). In the
OSS environment, the term “user ID” usually refers to the single number that is the scalar view
of the user ID—a number called the UID. See also UID.
volume A logical disk, which can be one or two magnetic disk drives. In HP NonStop S-series systems,
volumes have names that begin with a dollar sign ($), such as $DATA.
waited I/O I/O operations for which the initiating process does not resume execution until the I/O operations
are completed. Contrast with nowait I/O.
521
522
Index
derived default base entries, 255
Symbols example of, 255
$0 collector process, 227 permissions for new files, 253
$RECEIVE, 110, 117, 164, 165, 176, 179, 235, 237, 277, 380 limits for, 250
example with OSS processes and Guardian procedures, NFS V2 clients and, 257
166, 172, 179 notation, 251
$ZAFN2, 178 on directories, 253
$ZLSnn, 176 OSS permissions and, 60
$ZPLS, 176, 177 present on a file, 60
/dev/tty, 195 Safeguard, 60
32-bit APIs (see Large File Safe (LFS)) setacl command, 256
64-bit APIs (see Large File Aware (LFA)) supported RVUs, 61
_exit() function, 142 types of files supported, 250
_INTEROPERABLE feature-test macro, 64 types of objects supported, 61
_PUT_MODEL_ macro access control lists (ACLs)
, 374 and NFS, 61, 250
_r in function names (see reentrant functions) access() function, 85, 87, 243
_TANDEM_SOURCE feature-test macro, 453 acl() function, 241, 243, 256
_XOPEN_SOURCE feature-test macro, 453 ACL-PRESENT flag, 60
_XOPEN_SOURCE_EXTENDED feature-test macro, 454 ACLs (see Access control lists (ACLs))
aclsort() function, 258
A add_define utility, 106
abort() function, 110, 141 ADDDSTTRANSITION procedure, 161
Absolute pathname, 28 AF_INET sockets, 163, 164, 165
Accelerator, 45, 47 AF_INET6 sockets, 164
accept() function, 177, 185 AF_UNIX sockets
Access control lists (ACLs) AF_UNIX Release 1, 176
access-checking algroithm, 256 AF_UNIX Release 2, 176
acl() function, 256 audited function calls, 243
ACL-PRESENT flag, 60 compatibility mode, 176, 177
aclsort() function, 258 Guardian sockets API, 165
and chmod() function, 257 interprocess communication using OSS and Guardian
and chown() function, 257 APIs, 164
and Network File System (NFS), 61 interprocess communication using OSS APIs, 163
and SECURITY-OSS-ADMINISTRATOR security OSS sockets local server ($ZPLS), 176
group, 61 OSS sockets local server 2 ($ZLSnn), 176
and stat() function, 256 portability mode, 176, 177
and utilities, 256 transport-provider name, 177, 178
and Version 3 filesets, 61 alarm() function, 141, 155, 159
compared to permissions, 249 Guardian processes, 156
copying, 256 ANSISTREAMS pragma , 62
disk volumes and, 61 API, 26
effect on pathnames, 61, 249 Application program interface (API), 25
entries Applications
actual, 253 block mode, 42
base, 251 development of, 35
base default, 253 ar utility, 43
class, 252 asctime() function, 155, 159
default, 253 Attributes, process, 105
nondefault, 253 setting, 113
optional, 252 AWAITIO/[X] procedures
example program, 258 with threads, 277, 380
getacl command, 256 AWAITIO\[X] procedures, 191
header file, 258 example, 66
inheritance AWAITIObk/[X] procedures, 94
and directories, 254
523
B Conforming POSIX.1 application, 27
bind() function, 185, 243 confstr() function, 87
BINSEM_CLOSE_ procedure, 191 connect() function, 177, 185, 245
BINSEM_CREATE_ procedure, 191 CONTROL procedure, 193, 223
BINSEM_FORCELOCK_ procedure, 191 example, 219
BINSEM_LOCK_ procedure, 192 CONTROLBUF procedure, 193
BINSEM_OPEN_ procedure, 192 Controlling processes
BINSEM_UNLOCK_ procedure, 192 example using the PROCESS_SPAWN_ procedure, 118
Bits, referring to, 41 Guardian processes
bk/G directory, 30, 52 example using Guardian procedures, 115
Block-mode applications, 42 using Guardian procedures, 115, 118
OSS processes, using Guardian procedures, 115, 118
C using OSS functions, 111
C development utilities, 43 Controlling terminal, 106
C functions, Guardian, use in OSS programs, 40 CONVERTPROCESSTIME procedure, 161
C modules, Guardian CONVERTTIMESTAMP procedure, 161
invoking, 41 CPUTIMES procedure, 161
systype guardian pragma, 41 creat() function, 87, 244
c89 utility, 41, 44, 236 creat64() function, 244
c99 utility, 41, 44, 236 Creating processes
Caching, file, 82 example using the PROCESS_SPAWN_ procedure, 118
CANCEL procedure, 192 Guardian processes
Cancelability example using Guardian procedures, 115
PUT Model library, 379 using Guardian procedures, 115
SPT library, 276 OSS processes
cancellation points example using the tdm_fork() and tdm_execvep()
, 357 functions, 111
potential, 358 example using the tdm_spawnp() function, 113
CANCELPROCESSTIMEOUT procedure, 161 using Guardian procedures, 115
CANCELREQ procedure, 192 performance considerations, 130
CANCELTIMEOUT procedure, 161 using OSS functions, 111
cextdecs.h library header file , 37 Cross compilation , 35
cfgetispeed() function, 221 Cross compiler, PC, 49
cfgetospeed() function, 221 crypt() function, 241
cfsetispeed() function, 221 ctermid() function, 87, 222
cfsetospeed() function, 221 ctime() function, 155, 159
chdir() function, 85, 245 CTOEDIT file-type conversion tool, 47
CHECKSETMODE procedure, 223 cuserid() function, 241
Child process, 34
CHILD_LOST_ procedure, 147 D
chmod() function, 86, 241, 244 Data buffer size and performance improvements, 183
ACLs and, 257 Data heap , 150
chown() function, 86, 241, 244 Debug options, Guardian process attributes for, 106
ACLs and, 257 Debuggers
chroot() function, 86, 245 Inspect, 45
clock() function, 155, 157, 159 Native Inspect, 45
close() function, 86 NSDEE debugging features, 46, 49
closedir() function, 87 Visual Inspect, 46
closelog() function, 226, 231, 232 Declarations, Guardian procedures, 37
Comma, as placeholder for optional Guardian parameter, DEFINEs, 106, 198
38 Guardian process attributes for, 106
Communications subsystems, accessing from OSS del_define utility, 106
programs, 235 Development, application, 35
Compilation tools DEVICE_GETINFOBYLDEV_ procedure, 223
Guardian, 47 difftime() function, 155
OSS, 43 Directory, 27
COMPUTEJULIANDAYNO procedure, 161 DLLs (see Dynamic-link libraries (DLLs))
COMPUTETIMESTAMP procedure, 161 dup() function, 87
Condition codes, Guardian procedure, OSS example, 38 Dynamic window
524 Index
Telserv, 198, 199 Fault isolation, 279, 380
Dynamic-link libraries (DLLs), 45 fchmod() function, 241, 244
fchown() function, 241, 244
E fclose() function, 87
EAGAIN error, 289, 345 fcntl() function, 87
EALREADY error, 296, 348 fd_count parameter, child process, 115
ECONNREFUSED error, 177, 178 fd_map parameter, child process, 115
ed line editor, 43 FE_ENOENT error, 177
EDIT files , 31 Feature-test macro, 453, 454
OSS access, 62 FIFO, 163, 164, 165
redirecting OSS output to, 202 File caching, 82
EDITTOC file-type conversion tool, 47 File descriptor
EINPROGRESS error, 289, 345 inherited from parent process , 115
eld utility, 44, 47 nonblocking, 289, 345
EMS File system, 28
collector processes , 226 Guardian, 29, 31
specifying from shell , 227 OSS, 27, 29
procedures, 225, 226 File types
access from OSS processes, 226 Guardian, OSS access, 31
tokens, logging parameter, 232 OSS, 28
EMS_COLLECTOR shell variable, 227 File-type conversion tools, 47
encrypt() function, 241 FILE_ALTERLIST_ procedure, 94
endgrent() function, 242 FILE_CLOSE_ procedure, 192
endhostent() function, 188 FILE_COMPLETE_ procedure, 94
endnetent() function, 188 FILE_COMPLETE_GETINFO_ procedure, 94
endprotoent() function, 188 FILE_COMPLETE_SET_ procedure, 95
endservent() function, 188 FILE_CREATE_ procedure, 95
enoft utility, 44, 47 FILE_CREATELIST_ procedure, 95
Enscribe functions, thread-aware, 370 FILE_GETINFO_ procedure, 95, 192
Environment example, 72
execution, 35 FILE_GETINFOBYNAME_ procedure, 95
process example, 36, 70
modifying, 127 FILE_GETINFOLIST_ procedure, 95
obtaining information about, 121 information provided, 35
source, 35 FILE_GETINFOLISTBYNAME_ procedure, 95
target, 35 FILE_GETLOCKINFO_ procedure, 95
Environment variables, 34 FILE_GETOPENINFO_ procedure, 95
Environment-specific parameters in functions, 64, 451 FILE_GETRECEIVEINFO_ procedure, 192
Epoch, 156 FILE_OPEN_ procedure, 95, 192
Error reporting in thread functions, 262, 330 example, 38, 66, 68, 72, 200, 216, 219
ETK, 49 used with audited file, 245
Event Management Service (EMS) (see EMS) FILE_OPEN_CHKPT_ procedure, 96
EWOULDBLOCK error, 289, 345 FILE_PURGE_ procedure, 96
Examples, programming, 15 FILE_RENAME_ procedure, 96
exec set of functions, 34, 105, 244 Filename
and threads, 279, 380 displaying Guardian filename corresponding to OSS
execl() function, 142 pathname, 54
execle() function, 142 displaying OSS pathname corresponding to Guardian
execlp() function, 142 filename, 54
Execution environment, 35 Guardian (see Guardian filenames)
Execution priority OSS, and disks, 27
changing, example, 128 FILENAME_TO_PATHNAME_ procedure, 96
process, changing, 106 example, 56
execv() function, 142 FILENAME_TO_PROCESSHANDLE_ procedure, 147
execve() function, 34, 142 Files
execvep() function, 142 accessing from Guardian API, 65
accessing from OSS API, 62
F EDIT
Facility, logging, 228 See EDIT files, 31
525
Guardian getpid() function, 143, 242
See Guardian files, 31 getppid() function, 143, 242
odd-unstructured, 31 getprotobyname() function, 189
OSS access, 62 getprotobynumber() function, 189
OSS getprotoent() function, 189
See OSS files, 55 getservbyname() function, 189
unstructured, 31 getservbyport() function, 189
Fileset, 28 getservent() function, 189
fopen() function, 87 getsid() function, 143, 242
fopen_guardian() function, 88 getsockname() function, 177, 185
fopen_oss() function, 88 getsockopt() function, 185
fork() function, 34, 98, 142, 244 gettimeofday() function, 159
performance considerations, 130 getuid() function, 143, 242
with threads, 279, 380 Global resources, 261, 332
fpathconf() function, 88, 222 globfree() function, 89
fread() function, 88 gmtime() function, 155
freeaddrinfo() function, 188 gname utility, 54
freehostent function, 188 Group ID, 32
fstat() function, 60, 88, 242 gtacl utility , 42
fstat64() function, 242 Guardian attributes
fstatvfs() function, 88, 242 OSS processes, 105
fstatvfs64() function, 242 setting, 106
fsync() function, 88 Guardian C functions, using in OSS programs, 40
ftime() function, 159 Guardian C modules
FTIOMODE attribute, 82 binding to OSS program, 41
ftok() function, 165, 185 compiling with systype pragma, 41
ftruncate() function, 88 invoking, 41
ftw() function, 89 systype guardian pragma, 41
Function Guardian DEFINE eq_AFUNIX_PROCESS_NAME, 177,
OSS, using, 35 178
with environment-specific parameters, 64, 451 Guardian environment
FUP INFO command, OSS file display, 55 Guardian processes, running with gtacl, 42
nesting, 52
G text-editor, 47
gai_sterr() function, 188 Guardian file system , 29
getacl command, 256 Guardian filenames, 29, 51
getaddrinfo() function, 188 corresponding pathnames, 54, 56
getcwd() function, 89 length, 52
getdate() function, 159 pathname translation rules, 53
getegid() function, 142, 242 Guardian files
getenv() function, 142 access, 31
geteuid() function, 143, 242 accessing from OSS API, 62, 63
getgid() function, 143, 242 RWEP, 31
getgrent() function, 242 security, 31
getgroups() function, 143, 242 Guardian parent process
gethostbyaddr() function, 188 ancestors, 34
gethostbyname() function, 188 OSS process, 117
gethostent() function, 188 Guardian procedures
gethostid() function, 188 bit references, 41
getipnodebyaddr function, 188 integer data type, 37
getipnodebyname() function, 189 prototype declarations, 37
getlogin() function, 242 using in OSS programs, 35
getnameinfo() function, 189 Guardian processes
getnetbyaddr() function, 189 attributes, 34
getnetbyname() function, 189 creating and controlling from OSS, example using
getnetent() function, 189 Guardian procedures, 115
getpass() function, 242 inheritance, 34
getpeername() function, 177, 189 modifying environment, 127
getpgrp() function, 143, 242 obtaining information about, 121
526 Index
OSS access, 105 Inheritance information, OSS, 111
OSS attributes, 105 Initializing logging parameters, 228
OSS child process times, 157 Inspect debugger, 45
processor time, 157 process blocking, 277, 380
redirecting OSS input and output, 202 Integer data type
running from OSS environment, 42 Guardian procedures, 37
Guardian security, 31 OSS C programs, 37
corresponding OSS file-access permission, 60 Interoperability
Guardian sockets, 166, 167 API
Guidelines for threaded application development, 276, in native processes, 451
378 in TNS processes, 427
file system, 63
H I/O management, 195
Header files, library , 35 interprocess communication, 165
Home terminal Guardian process attribute, 106 logging, 226
HP Enterprise Toolkit - NonStop Edition, 49 memory management, 150
HP extension functions , 34 process management, 107
HP NonStop SQL/MP, accessing from OSS programs, 236 redirecting I/O to Guardian objects, 202
HP NonStop SQL/MX, accessing from OSS programs, signals, 110
236 time management, 156
HP NonStop subsystems INTERPRETINTERVAL procedure, 161
accessing from OSS programs, 235 INTERPRETJULIANDAYNO procedure , 156, 161
communications, accessing from OSS programs, 235 INTERPRETTIMESTAMP procedure, 161
HP NonStop TMF, accessing from OSS programs, 237 Interprocess communication
HP NonStop TS/MP, accessing from OSS programs, 236 between nodes, 179
HP NonStop Tuxedo system, accessing from OSS between processors, 163, 164
programs, 237 example with OSS processes and Guardian procedures,
HP Tandem Development Suite (TDS), 49 166
HP Tandem LAN Access Method (TLAM), accessing from performance considerations, 183
OSS programs, 235 UNIX differences, 165
htonl() function, 190 using a $RECEIVE file, 179
htons() function, 190 ioctl() function, 89
isatty() function, 222
I
I/O J
balancing read and write operations, and performance Jacket routines, 276, 378
improvement, 183 JULIANTIMESTAMP procedure, 157, 161
printing, 214, 215, 221
example, lp utility with popen() function, 214 K
redirecting to Guardian objects, 202 kill() function, 110, 143, 244
tape, 196
example, pax utility with popen() function, 197 L
terminal, 198 Labeled tape
control characters, 199 and OSS files, 198
example, 200 LABELEDTAPESUPPORT procedure, 223
if_freenameindex() function, 189 Large File Aware (LFA)
if_indextoname() function, 189 APIs provided by HP, 77
if_nameindex() function, 189 definition, 75
if_nametoindex() function, 189 Large File Safe (LFS)
inet_addr() function, 190 APIs provided by HP, 75
inet_lnaof() function, 190 definition, 75
inet_makeaddr() function, 190 Large files (see also OSS files, large files)
inet_netof() function, 190 access from systems without large file support, 77
inet_network() function, 190 accessing from systems without large file support, 75
inet_ntoa() function, 190 and 64-bit APIs, 75
inet_ntop() function, 190 and FILE_OPEN, 78
inet_pton() function, 190 and FILE_OPEN_ error 580, 79
inherit structure, 115 Guardian files created by OSS APIs, 78
tdm_spawn() and tdm_spawnp() functions, 111 size limit, 74
527
underlying Guardian file format, 74 versus single-threading, 280, 381
lchmod() function, 241, 244 Mutex
lchown() function, 241, 244 to protect context, 277, 379
ld utility, 44, 47 to protect shared data, 277, 379
lex utility, 43 with multiple interdependent threads, 280, 382
Library MYPROCESSTIME procedure, 156, 161
standard and threaded applications, 276
standard, and single-threading, 279, 381 N
threads, 261, 281, 329, 368 Name, process, setting, 113
Library functions, 35 Native Inspect debugger, 45
Library header files, 35 Native process, 34
link() function, 89, 244 Nesting, 52
Linking C modules, OSS, 44 Network File System (NFS), 245
listen() function, 177, 178, 185 NFS, 245
localtime() function, 155, 159 nftw() and nftw64() functions, 90
LOCKFILE procedure, 96 nftw() function, 144
LOCKREC procedure, 96 nftw64() function, 144
LOG_WARNING, severity level, 227 nice() function, 103, 105
Logging, 227 nld utility, 44, 47
facility, 228 nm utility, 43
functions, calling from Guardian module, 226 noft utility, 44, 47
interoperability, 226 Nonblocking I/O functions, 289, 345
parameters, initializing , 228 PUT Model library, 346
longjmp() function, 143, 278, 337 NonStop Development Environment for Eclipse (NSDEE),
lp utility, example with popen() function, 214 49
lseek() and lseek64() functions, 89 NORMALIOMODE attribute, 82
lstat() and lstat64() functions, 90 Nowait I/O, 277, 280, 380, 381
lstat() function, 242 Nowait Ibk/O, 65
lstat64() function, 242 Nowait OSS process creation, 117
NSDEE, 49
M ntohs() function, 190
make utility, 43
Measure product , 48, 156 O
Memory O_NONBLOCK flag, 289, 345
data heap, 150 O_SYNC file open flag, 82, 83
manipulating with both OSS functions and Guardian Object Code Accelerator (OCA), 47
procedures, 178 Odd-unstructured files, 31
sharing, 165 OSS access, 62
and synchronizing, 150, 178 Open System Services (OSS), 25
UNIX differences , 150 Open Systems Interconnection/Application Services
Message queues, 163, 164, 165 (OSI/AS), accessing from OSS programs, 235
MESSAGESTATUS procedure, 193 Open Systems Interconnection/Message Handling System
mkdir() function, 90, 242, 244 (OSI/MHS), accessing from OSS programs, 235
mkfifo() function, 185, 244 open() and open64() functions, 90
mknod() function, 90, 244 open() function, 90, 244
mkstemp() function, 90 Guardian files, 63
mktime() function, 155, 160 open64() function, 244
Modules, Guardianbk/ C opendir() function, 91, 244
binding to OSS program, 41 openlog() function, 226, 227, 228, 232
compiling with systype pragma, 41 Optimizer, 45
MOM process, 34 OSI/AS, accessing from OSS programs, 235
MONITORCPUS procedure , 118 OSI/MHS, accessing from OSS programs, 235
msgctl() function, 185 OSS C programs, integer data type, 37
msgget() function, 185 OSS child processes, monitoring by reading $RECEIVE,
msgrcv() function, 186 117
msgsnd() function, 186 OSS environment
Multithreading Guardian command, piping output, 42
independent application threads, 280, 381 TACL process, starting from, 42
interdependent application threads, 280, 382 text-editing tools, 43
528 Index
OSS file system, 27 OSS requesters, not supported by HP NonStop/TM TS/MP
directories, 52 , 236
nesting, 52 OSS servers, monitoring with HP NonStop/TM TS/MP ,
UNIX differences, 62 236
OSS files OSS_PID_NULL_ procedure, 147
FUP INFO command display, 55 OSSTTY facility;Interoperability
information with Guardian procedure by name, 70, 72 using OSSTTY, 202
information with Guardian procedure by number, 72
labeled-tape operations, 198 P
large files, 74 Parameters, optional Guardian,
printing from program, 214 comma as placeholder for, 38
reading with Guardian procedure, nowait mode, 68 Parent process, 34
reading with Guardian procedure, wait mode, 69 pathconf() function, 91, 222
sending directly to printer, 219 Pathname, 28, 51
sending to Guardian print spooler, 216 corresponding Guardian filenames, 54, 55
size limits, 62 from Guardian filename with FUP INFO DETAIL, 55
small files, 74 Guardian filename translation rules, 52
types, 28, 62 length, 52
OSS functions, use in programs, 35 relative, Guardian translation, 53
OSS HP extension functions, process management, 105 PATHNAME_TO_FILENAME_ procedure, 96, 130
OSS logging example, 55, 70
facility, 228 Pathway server
functions, calling from Guardian module , 226 and SERVERCLASS_DIALOG, 281, 368
parameters and SERVERCLASS_SEND_, 281, 368
default values, 227 and SERVERCLASS_SENDL_, 281, 368
initializing , 228 process blocking, 277, 380
severity level, 227 pause() function, 144
UNIX differences, 226 pax utility, example with popen() function, 197
OSS module PC cross compiler, 49
environment, 451, 452 pclose() function, 186
OSS pathnames, 51 Performance analyzer, 48
OSS process handle, 105 Performance considerations
OSS process ID, 32, 105 file system functions, 82
OSS processes, 202 fork() function , 130
accessing EMS procedures , 226 interprocess communication , 183
attributes, 34 process creation, 111, 130
controlling process management , 130
example using the PROCESS_SPAWN_ procedure, tdm_fork() function , 130
118 tdm_spawn() function , 130
using Guardian procedures, 117 tdm_spawnp() function , 130
creating, 111 workload distribution, 130
example using the PROCESS_SPAWN_ procedure, Permissions, OSS
118 corresponding Guardian security, 60
example using the tdm_fork() and tdm_execvep() FUP INFO display, 55
functions, 111 permission bits, 29
example using the tdm_spawnp() function, 113, 115 perror() function, 232
nowait manner, 117 Persistent process, 117
using Guardian procedures, 117 PIC (see Position-independent code (PIC))
environment , 452 Pipe, 163, 164, 165
Guardian access, 105 pipe() function, 91, 186, 245
Guardian parent, 117 Piping Guardian output, 42
inheritance, 34 pname utility, 54
modifying environment, 127 popen() function, 186
obtaining information about, 121 example with lp utility, 214
example with PROCESS_GETINFOLIST_ procedure, example with pax utility, 197
125, 127 Portability of threads, 275, 356
operator messages, receiving, 225 Position-independent code (PIC), 45
UNIX differences, 97 POSIX standards, 26, 27
POSIX Threads (see Threads)
529
Pragmas example, 118
SYSTYPE GUARDIAN, 41 used with audited file, 245
SYSTYPE OSS, 41 PROCESS_STOP_ procedure, 147
Printers example, 115
/G directory inaccessibility, 219 PROCESS_SUSPEND_ procedure, 147
control codes, 219 example, 115
sending OSS files directly to, 219 Processes, 31
Printing, 215 controlling
example, lp utility with popen() function, 214 See Controlling processes, 111
OSS utilities only, 195 creating
Priority See Creating processes, 111
Guardian process attribute, 106 Guardian
process execution, 106 See Guardian processes, 105
Private resources, 261, 332 identification, 32
Procedure, Guardian modifying environment, 127
condition code obtaining information about
and return value, 36, 40 environment, 121
OSS example, 38 example with PROCESS_GETINFO_ procedure, 123
return value OSS
and condition code, 36, 40 See OSS processes, 105
OSS example, 36 persistent, 117
use in OSS programs, 35 pipes and FIFOs on same processor, and performance
Process attributes, 105 improvements , 183
setting, 113 PROCESSHANDLE_COMPARE_ procedure, 147
Process environment PROCESSHANDLE_DECOMPOSE_ procedure, 148
modifying, 127, 130 PROCESSHANDLE_GETMINE_ procedure, 148
obtaining information about, 121 PROCESSHANDLE_NULLIT_ procedure, 148
OSS, 34 PROCESSHANDLE_TO_CRTPID_ procedure, 148
Process group, 32 PROCESSHANDLE_TO_FILENAME_ procedure , 148
Process handle, 32 PROCESSHANDLE_TO_STRING_ procedure, 148
OSS process, 105, 107 PROCESSNAME_CREATE_ procedure , 148
Process ID, OSS, 105 Processor
Process identifiers, 32 Guardian process attribute, 106
Process management process execution, 106
OSS HP extension functions, 105 Processor time, limiting, example , 157
performance improvement, 130 PROCESSOR_GETINFOLIST_ procedure, 162
Process name, 32 PROCESSSTRING_SCAN_ procedure , 148
setting, 113 Programmatic interfaces, 55
Process pairs, 34 Programming examples, 15
Process priority, modification by OSS process, 105 Programming, UNIX, books, 15
Process resources, 276, 378 Prototype declarations for Guardian procedures, 37
Process-blocking calls, from threads, 277, 380 Pthread functions, 261, 329
Process-blocking I/O function, 288, 345 pthread.h header file, 329
PROCESS_ACTIVATE_ procedure, 147 pthread.h header files, 374
example, 115 pthread_yield function (sched_yield), 261
PROCESS_CREATE_ procedure PUT Model library
example, 115 $RECEIVE I/O, 364
PROCESS_DEBUG_ procedure, 147 _PUT_MODEL_ define, 329
PROCESS_GETINFO_ procedure , 122, 147, 156, 161 _PUT_MODEL_ macro, 374
example, 123 _PUT_SELECT_SINGLE_ define, 330
PROCESS_GETINFOLIST_ procedure , 118, 123, 147, 156, and reentrant functions, 359
161 attributes defined by macros, 331
example, 125 build script, 374
PROCESS_GETPAIRINFO_ procedure, 147 cancel requests, 379
PROCESS_SETINFO_ procedure , 106, 130, 147 cancellation points, 357
example, 128 concurrency level, default, 375
PROCESS_SETSTRINGINFO_ procedure, 147 converting to from SPT, 373
example, 128 Enscribe functions, thread-aware, 370
PROCESS_SPAWN_ procedure, 117, 147, 237 Environment variables, 330
530 Index
file descriptor and timer callbacks, 372 reentrant functions
header file, 329, 374 definition of, 313, 359
header files, 374 H06.21 and later H-series RVUs, 359
incompatibility with SPT library, 329 J06.10 and later J-series RVUs, 359
nonblocking, 345 Relative pathname, 28
nonblocking functions, 346 Guardian translation, 53
numerical limits, 333 remove() function, 92
portability of, 356 rename() function, 92, 244
potential cancellation points, 358 rename_oss() function, 92
process resources, use of, 378 REPLYX procedure, 192
protected signal stack, 336 Resource types, 261, 332
serializing file operations on open regular files, 345 retcode, 37
SERVERCLASS_DIALOG jacket routines, 368 Return value
SERVERCLASS_SEND jacket routines, 368 changes for thread functions, 262, 330
SERVERCLASS_SENDL jacket routines, 368 Guardian procedure, OSS example, 36
signals, 335, 337 rewinddir() function, 92
standard and nonstandard types, 375 rmdir() function, 92, 242, 244
standards conformance, 330 Root directory, 27
supported RVUs, 329
thread safety, 356 S
thread unsafe functions, 357 S_NONSTOP attribute
thread-aware functions, 346 performance and reliability considerations, 83
thread-aware I/O, disabling, 345 S_NONSTOP file open flag, 82, 83
thread-aware toolkit functions, 361 Safeguard
TMF jacket routines, 369 access control lists (ACLs), 60
ZPUTDLL, 329 using for file audit reduction, 239
PUT_ABORTTRANSACTION() function, 369 using to administer users and groups, 239
PUT_BEGINTRANSACTION() function, 369 using to protect disk volumes, 61
PUT_ENDTRANSACTION() function, 369 scandir() and scandir64() functions, 92
put_extensions.h header file, 374 sched_yield function, 261, 278, 280, 329, 380, 381
PUT_PROTECTED_STACK_DISABLE, 330 Scheduling priority, 105
PUT_RESUMETRANSACTION() function, 369 Security, Guardian and OSS permissions, 60
PUT_SERVERCLASS_DIALOG_ABORT_() function, 369 sed stream editor, 43
PUT_SERVERCLASS_DIALOG_BEGIN_() function, 369 seekdir() function, 92
PUT_SERVERCLASS_DIALOG_END_() function, 369 SEGMENT_ALLOCATE_ procedure, 192
PUT_SERVERCLASS_DIALOG_SEND_() function, 369 SEGMENT_DEALLOCATE_ procedure, 192
PUT_SERVERCLASS_SEND_() function, 368 SEGMENT_USE_ procedure, 192
PUT_SERVERCLASS_SEND_INFO_() function, 368 select() function, 92
PUT_SERVERCLASS_SENDL_() function, 368 Semaphore, 163, 164, 165
PUT_THREAD_AWARE_REGULAR_IO_DISABLE, 330 semctl() function, 186
put_types.h header file, 374 semget() function, 186
putenv() function, 144 semop() function, 186
send() function, 186
R sendmsg() function, 186
raise() function, 110, 144, 279, 337 sendto() function, 186
read() function, 91 Server class, 237
readdir() and readdir64() functions, 91 Server process, interprocess communication examples,
readlink() function, 91 166
READLOCKX procedure, 96 SERVERCLASS_DIALOG routines, 281, 368
READUPDATELOCKX procedure, 96 SERVERCLASS_SEND_ function, 281, 368
READUPDATEX procedure, 192 SERVERCLASS_SENDL_ function, 281, 368
readv() function, 91 setacl command, 256
READX procedure, 193 setgid() function, 144, 242, 244
example, 38, 66, 68, 200 setgrent() function, 242
recv() function, 186 sethostent() function, 190
recvfrom() function, 177, 178, 186 setjmp() function, 144, 278, 337
recvmsg() function, 177, 178, 186 setkey() function, 242
Redirecting I/O to Guardian objects, 202 setlogmask() function, 226, 227, 232
redirecting I/O to Guardian objects, 202 SETLOOPTIMER procedure, 148, 162
531
OSS processes, 156 socket_transport_name_set() function, 177, 178, 188
example, 157 socketpair() function, 92, 187
SETMODE procedure, 96, 193, 223 sockets
SETMODENOWAIT procedure, 193, 223 AF_INET
setnetent() function, 191 See AF_INET sockets, 165
SETPARAM procedure, 193 AF_INET6
setpgid() function, 144, 242, 244 See AF_INET6 sockets, 166
setpgrp() function, 144, 244 AF_UNIX
setprotoent() function, 191 See AF_UNIX sockets, 176
setregid() function, 144, 242, 244 Source environment, 35
setreuid() function, 144, 242, 244 spawn.h library header file , 115
setservent() function, 191 Spawning a new process, and threads, 279, 380
setsid() function, 144, 242, 244 Specifications, XPG4, 26
setsockopt() function, 186 Spooler, Guardian print, sending OSS files to, 216
SETSYSTEMCLOCK procedure, 162 SPT_ABORTTRANSACTION() function, 282
setuid() function, 144, 242, 244 spt_alarm() function, 267
example, 128 SPT_BEGINTRANSACTION() function, 282
Severity level, events, 227 SPT_ENDTRANSACTION() function, 282
Shared memory , 163, 164 spt_extensions.h header file, 374
shmat() function, 187 SPT_RESUMETRANSACTION() function, 282
shmctl() function, 178, 187 SPT_SERVERCLASS_DIALOG_ABORT_() function, 282
shmdt() function, 187 SPT_SERVERCLASS_DIALOG_BEGIN_() function, 281
shmget() function, 187 SPT_SERVERCLASS_DIALOG_END_() function, 282
sigaction() function, 145, 263, 334 SPT_SERVERCLASS_DIALOG_SEND_() function, 281
used with threads, 278, 336 SPT_SERVERCLASS_SEND_() function, 281
SIGACTION_INIT_ procedure, 148 SPT_SERVERCLASS_SEND_INFO_() function, 281
SIGACTION_RESTORE_ procedure, 148 SPT_SERVERCLASS_SENDL_() function, 281
SIGACTION_SUPPLANT_ procedure, 148 spt_signal() function, 267
sigaddset() function, 145 spt_sigwait() function, 263
sigdelset() function, 145 spt_star() functions, 290
sigemptyset() function, 145 spt_starx() functions, 290
sigfillset() function, 145 spt_starz() functions, 289, 290
sigismember() function, 145 mixed mode applications, 296
SIGJMP_MASKSET_ procedure, 148 serialization of file operations, 289
siglongjmp() function, 145 spt_types.h header file, 374
Signal, 111 spt_ucontext.h header file, 374
compared to trap, 110 spthread.h header file, 262
handler, default, 110 SQL compiler, 44, 236
threads with, 279, 337 SQL databases, accessing from an OSS program , 236
Signal mask, 278, 337 SQL objects, catalogs, and programs, information from
signal() function, 145 an OSS program , 236
SIGNALPROCESSTIMEOUT procedure, 162 Standard POSIX Threads functions, 261
SIGNALTIMEOUT procedure, 162 Standards, POSIX, 26
sigpending() function, 145 stat() and stat64() functions, 93
sigprocmask() function, 145 stat() function, 60, 242
sigsetjmp() function, 145 ACLs and, 257
sigsuspend() function, 145 information provided, 35
sigwait() function, 334 stat64() function, 242
Single-threading versus multithreading, 279, 381 Static window
sleep() function, 110, 145 Telserv, 198
Small files (see OSS files, small files) statvfs() and statvfs64() functions, 93
and 64-bit APIs, 74 strerror() function, 233
size limit, 74 strftime() function, 155, 157, 160
underlying Guardian file format, 74 strip utility, 43
SNAX Extended Facility (SNAX/XF), accessing from OSS strptime() function, 156, 160
programs, 235 Subdirectories, 52
sockatmark() function, 187 Super ID, 239
socket() function, 92, 187 Symbolic debuggers, 45
socket_transport_name_get() function, 188 symlink() function, 93, 244
532 Index
sysconf() function, example, 122 using OSSTTY, 205
syslog() function, 226, 227, 229, 233 Text-editing tools
System functions, 35 Guardian, 47
System limits, system-dependent, obtaining, example, OSS, 43
122 Thread functions, 261, 329
SYSTYPE pragma, 41 Thread-aware OSS functions
$RECEIVE I/O, 320, 364
T contrasted to process-blocking functions, 288, 345
TACL processes, starting from OSS environment, 42 file descriptor, 326, 372
tal.h library header file, and condition codes, 39 for non-regular files, 290, 346
Tape I/O, 196 for regular files, 289, 345
example, pax with popen() function, 197 timer callbacks, 326, 372
OSS utilities only, 195 toolkit, 316, 361
pax utility, 196 using, 296, 348
Target environment, 35 Thread-blocking I/O function (see Thread-aware OSS
tcdrain() function, 222 functions)
tcflow() function, 222 Threading considerations, 276, 378
tcflush() function, 222 Threads
tcgetattr() function, 222 compiling and binding , 262, 281, 282, 329, 369
TCP/IP error reporting, 262, 330
accessing from OSS programs, 235 NonStop server implementation, 261, 329
tcsendbreak() function, 222 portability, 275, 356
tcsetattr() function, 222 signals, 263, 278, 334, 335
tdm_execep() function, 279, 380 protected stack, 336
tdm_execve() function, 105, 145, 279, 380 PUT Model library signal stack, 336
used with audited file, 244 single versus multiple, 280, 381
tdm_execvep() function, 105, 145 stack addressability, 277, 379
example, 111 Time management, UNIX differences, 156
used with audited file, 244 TIME procedure, 162
tdm_fork() function, 34, 105, 146 time() function, 155, 160
example, 111 times() function, 146, 155, 157, 160
performance considerations, 130 in Guardian process, 156
used with audited file, 245 timespec_t type, 375
used with threads, 279, 380 TIMESTAMP procedure, 162
tdm_spawn() function, 105, 146 Timestamps , 156
performance considerations, 111, 130 TLAM, accessing from OSS programs, 235
used with audited file, 245 TMF jacket routines for threads, 282, 369
tdm_spawnp() function, 105 TNS process, 34
example, 113, 115 TNSE native process, 34
performance considerations, 111, 130 TNSR native process, 34
used with audited file, 245 Tools
tdm_spawnp(2) function, 146 development
tdmext.h library header file , 113 Guardian, 47
TDS, 49 OSS, 42
TEDIT full-screen text editor, 47 multienvironment, 41
telldir() function, 93 text-editing
Telserv windows, 198 Guardian, 47
Terminal OSS, 43
control characters, 199 Transaction jackets for threads, 282, 369
Guardian, accessing with Guardian procedures, Trap, compared to signal, 110
example, 200 tty command, 130
names, 130 ttyname() function , 130, 222
Terminal I/O, 198 tzset() function, 156, 160
/dev/tty, 195
canonical mode, 199 U
interoperability, 195 ulimit() function, 93
network terminals only, 195 umask() function, 93
noncanonical mode, 200 uname() function, 146
UNIX differences, 195 unlink() function, 93, 245
533
Unstructured file, 31
Unsupported utilities, 15
User ID, example of setting with setuid(), 128
Utilities
development, 43
unsupported, 15
utime() function, 93, 156, 160, 245
Guardian files, 156
V
vi screen-oriented line editor, 43
Visual Inspect debugger, 46
W
wait() function, 146
waitpid() function, 146
wcsftime() function, 160
Windows, multiple, 42
Workload distribution, performance considerations, 130
write() function, 94
WRITEREADX procedure, 192
example, 202
WRITEUPDATEUNLOCK\[X] procedure, 96
writev() function, 94
WRITEX procedure, 193
example, 219
X
X.25 Access Method (X25AM), accessing from OSS
programs, 235
XPG4 specifications, 26, 165
Y
yacc utility, 43
Yielding control by threads, 278, 280, 380, 381
Z
ZPUTDLL, 329
534 Index
535