Unix Environment Advanced Programming Chapter 2 U N i X Standardization and Implementation

xiaoxiao2021-03-05  49

Download Chapter 2 U N i X Standardization and Implementation 2.1 Introduction The standardization of U N i x and c programming languages ​​has been done a lot. Although the u N i x application is relatively easy to transplant between different U N i X versions, the population of U N i x version of the 80s and the expansion between them cause many large users (such as the US government) to standardize them. This chapter will introduce a variety of standardization work, and then discuss the impact of these standards to the actual U N i x realization listed in this book. An important part of all standardized work is a description of each limit that must be defined for each implementation, so we will explain that these restrictions and a variety of ways to determine their values. 2.2 UNIX Standardization 2.2.1 ANSI C1 9 8 9 years later, C programming language A N S I standard x 3. 1 5 9 - 1 9 8 9 Get approval [ANSI 1989]. This standard has been adopted for international standard ISO / IEC 9899: 1990. A N S I is a US National Standard Society that is a non-profit organization consisting of manufacturers and users. In the United States, it is a national unpaid standard switching station that represents members of the United States in the International Standardization Organization (I S O). The intent of the ANSI C standard is to provide the portability of the C program, which makes it suitable for a large number of different operating systems, not just UN i X. This standard not only defines the syntax and semantics of the C programming language, but also defines its standard library [ANSI 1989 Chapter 4; Plauger 1992; Kernighan and Ritchie 1988] Appendix B]. Because many new U N i x systems (such as a few U N i x systems introduced by this book) provide library functions illustrated in the C standard, this library is important to us. The library can be divided into 1 5 districts according to each header file defined by this standard. The header files defined by the C standard definition in Table 2 - 1 are listed in Table 2 - 1, and the header files defined by the other two standards (P O S i x. 1 and x p g 3) described in the following sections. There are also headers supported by S V R 4 and 4. 3 B S D. This chapter will also perform the two U N i X implementations.

Table 2-1 Implementation of the header file standards for various standards and implementations ANSI CPOSIX. 1 xpg 3 SVR 4 4. 3 BSD • • • Verify assertions • • • CPIO Archive value • • • Character type • • • • Directory item (4. 2 1) • • • Error code (1. 7) • • • • File Control (3. 1 3) • • • Floating point constant • • File Tree roam (4. 2 1) (continued) header file standard implementation Description ANSI CPOSIX. 1 XPG 3 SVR 4 4. 3 BSD • • • Group File (6. 4) • • Language Information Constant • • • Implementation Constant (2. 5) • • • Local category • • • Mathematical constant • • Message category • • • • Password file ( 6. 2) • • • Regular expression • • Search table • • • Non-local GOTO (7. 1 0) • • • • • • Signal (Chapter 1 0) • • • Variable parameter table • • • Standard definition • • • Standard I / O library (Chapter 5) • • • Common functions • • • String operation • • TAR Archive value • • • Terminal I / O (Chapter 11) • • • Time and Date (6. 9) • • User Limits • • • • • Symbol constant • • • • • • • Document time (4. 1 9) • • • IPC (1 4. 6) • • Message Queue (1 4. 7) • • Sample (1 4. 8) • • • Share Storage (1 4. 9) • • • • File Status (4th 4 Chapter) • • • • Process Time (8. 1 5) • • • • • Original System Data Type (2. 7)

• • System Name (6. 8) • • • • Process Control (8.6) 2.2.2 IEEE POSIXP OSIX is a standard developed by IEEE (Electrical and Electronic Engineer Society) Family. P O S i X means the portable operation system interface for Computer Environment. It refers to only I E E E standard 1 0 0 3. 1 - 1 9 8 8 (operating system interface), but I E E e is currently developing other relevant standards in the P O S i X family. For example, 1 0 0 3. 2 will be a standard for SHE L L and utilities, 1 0 0 3. 7 will be standard in system management. At least 1 5 subcommittees in the Working Group in the Working Group. In line with this book, 1 0 0 3. 1 Operating System Interface Standard, the standard defines the "P O S i X" operating system must 1 8 u n i x Environment Advanced programming download provides services. Although 1 0 0 3. 1 standard is based on U N i x operating system, but it is not limited to U N i x and a system similar to U N i X. Indeed, some manufacturers who supply a proprietary operating system also claim that these systems will be in accordance with P O s i x (all proprietary functions thereof). Since 1 0 0 3. 1 standard illustrates an interface (I N T E R F A C E) instead of an implementation (I m P L E M e n t a t i o N), the system call and library function are not distinguished. All routines in the standard are called functions. Standard is constantly evolving, 1 0 0 3. 1 standard is no exception. The standard 1 988, IEEE 1003.1-1988 is submitted to I S O, no new interface or function is added, but the text is modified. The final document is officially published as IEEE STD.1003.1-1990 [IEEE 1990], which is the international standard ISO / IEC 9945-1: 1990. This standard is often referred to as P O S i x. 1, this book will use this standard. IEEE 1003.1 Working Group has made more modifications to them, they were approved in 1 993. These modifications (now referred to as 1 0 0 3. 1 a) should be published by IEEE as an IEEE standard 1 0 0 3. 1 - 1 9 9 0 attachment, these modifications have also impact on this book, mainly because Berkeley Style symbolic links are likely to be added to the standard as a requirement. These modifications are also likely to be an appendix for ISO / IEC 9945-1: 1990. This book will explain the 1 0 0 3 of P O S i x. 1 by the method of the comment, pointing out which functions are likely to add 1 0 0 3. 1 a. P O S i x. 1 does not include a concept of superuser. In order to specify certain operation requirements "appropriate priority", P O S i x. 1 will explain this definition of this term. Some U N i x systems that meet the security guidelines for the Ministry of Division have many different security levels. This book still uses traditional U N i x terminology and indicates the operation of the super user privilege. 2.2.3 X / Open XPG3X / O P E N is an international computer manufacturer organization. It proposed a 7-volume Billive Transplant Guide X / Open PortabilityGuide (X / O P E N Delivery Guide) Item 3 [X / Open 1989], we call it X P g 3.

X P G 3 Volume 2 XSI System Interface and Headers defines an interface for systems similar to U N i x, which is developed on the basis of the IEEE STD.1003.1-1988 interface. X P G 3 contains some of the features that P O S i x. 1. For example, P O S i x. 1 does not have a function of X / O P e n, which can be used to display text messages in different languages ​​in different languages. The X P G 3 interface uses the ANSI C draft instead of the final formal standard, some of the features included in the X P G 3 interface specification are no longer used. These issues are likely to be solved in the new version of the future X P g specification. (About XPG 4 is working, may be completed in 1 993.) 2.2.4 FIPSF IPS The meaning of FIPSF IPS is Federal Information Processing Standard, which is published by the US government, and by the United States. The government is used in the purchase of computer systems. F I P S 1 5 1 - 1 (1 98 9) Based on I E E ES T D. 1 0 0 3. 1 - 1 9 8 8 and ANSI C. FIPS 151-1 requires some options in P O S i x. 1. This F i P S is sometimes referred to as POSIX.1 FIPS. 2. The selection items required for the P O S i x. 1 required by F I P S are listed. The impact of POSIX.1 FIPS is: it requires either hope to sell P O S i x to the US government. 1 Computer system of computers should support certain options for P O S i x. 1. We will not treat POSIX.1 FIPS as another standard, because it is actually just a more stringent P O S i x. 1 standard. 2.3 Unix Implementation The above section describes three standards made by their independent organizations: ANSI C, IEEE POSIX and X / O P Chapter 2 U N i x Standardization and Implementation 1 9 Download x P G 3. However, the standard is just a specifications of the interface. How do these standards related to the real world? These standards are adopted by the manufacturer and then transition into specific implementation. In this book, we are interested in these standards and their specific implementation. Detailed history and relationship diagram of the U N i X tree is given in 1. 1 section of LE Ffler, 1. 1. All versions and variants of UNIX originate from the 6th edition (1 9 76) and 7th edition (1 979) (1 979) (1 979) (usually called V 6) on the PDP - 11 system And V7). These two versions are first widely used in the Bell Labs. From this tree, three branches have been developed: (a) AT & T branch, exported to system III and system V (called UNIX commercial version), (b) California University Berkeley branch, from now on exported 4 . x BSD implementation, (c) Unix research versions developed by the AT & T Bell Laboratory Research Center, from now on, from now 8, 9, and 1 0. 2.3.1 SVR4S VR 4 is a product of the AT & T UNIX system laboratory, which brings together the following systems: AT & T UNIX System V No. 3.2 (SVR 3. 2), Sun's S U NOS system, California University Berkeley's 4. 3 BSD and Microsoft's X Enix System (Xenix is ​​developed on the basis of V7, and later uses a lot of system V's functionality). Sourcecodes were distributed in late 1989, and in 1990 began to provide end users.

SVR4 complies with the POSIX 1003.1 standard and X / Open XPG3 standards. AT & T also published system V interface definition (S V i d) [AT & T 1989]. S V i D 3rd edition illustrates the function of the U N i x system to reach S V R 4 quality requirements. Like P O S i x. 1, S V I D illustrates an interface instead of an implementation. For a specific implementation S V R4, you should look at its reference manual to understand its differences [AT & T 1990E]. S V R 4 contains the compatibility library of B S D [AT & T 1990C] provides functions and commands corresponding to 4. 3 B S D. However, some of these functions are different from the corresponding part of P O S i x, and all S V R 4 instances in this book use this compatible library. Only if you have some early applications, you don't want to change them, it is recommended to use this compatible library, and new applications should not use it. 2.3.2 4.3 BSDB S D is research and development and distribution of computer system research teams from the University of California. 4. 2 B S D came from 1 9 83 years, 4. 3 B S D was in 1 986 years. These two versions are running on the VA X miniature. The next version of the next version 4. 3 BS DTA Ho was released in 1 988, in a small machine called TA HoE (LE E FF LER et al. [1 9 8 9] illustrated 4.3bsd Ta Hoe Version). Thereafter, there are 4.3BSD RENO versions in 1 990, which supports many features of P O S i x. 1. The next major version 4. 4 B S D should be released in 1 9 92. Early B S D systems contain AT & T proprietary source code, which requires AT & T licenses. In order to obtain the source code of the B S D system, the U N i x license of AT & T is required. This situation is being changed. In recent years, the AT & T source code is being converted into non-AT & T source code, and there are many new features that are added to the BSD system from non-AT & T. . 1 989, Berkeley put many non-AT & T source packages in 4.3bsd TA H O e into B S D network software, 1. 0, and make it a public available software. Thereafter, there is a BSD network software 2. 0, it is exported from 4.3bsd reno, its purpose is to make most (if not all) 4. 4 BSD system is no longer limited by the AT & T license Then, all of its source code can be used for the public. As explained in the preface, the book uses the term 4. 3 b S D represents the B S D system, the system is located between the B S D network software 2. 0 and the upcoming 4. 4 B S D. U N i x development work in Berkeley is starting from P D P - 11, then transferred to the VA X miniature, and then transferred to the workstation. In the early 1990s, Berkeley was supported on a wide range of applications 8 0 3 8 6 personal computers to develop B S D version 2 0 u n i x Environment Advanced programming download book, resulting 3 8 6 B S D. This work is done by Bill Jolitz. Its related documentation has a series of articles on the 1 9 91st D R.dobb's Journal (one one). Many of the code appears in the B S D Network Software 2. 0. 2.4 The relationship between standards and implementations We have already mentioned the standards of any actual system. Although IEEE POSIX is committed to formulating standards in other desired aspects (for example, communication between network interfaces, processes, system management), these standards do not exist when writing this book. This book is set in the two actual U N i x systems: S V R 4 and 4. 3 B S D.

Because these two systems declared that it is based on P O S i x, we focus on the functionality required by P O S i x. 1 standard, but also points out the difference between the P O S i X and the specific implementation of the two systems. Therefore, S V R 4 or 4. 3 B S D unique features and routines are clearly marked. Since X P G 3 is a supercoming of P O S i x. 1, we will also describe the functionality that belongs to X P G 3, but does not belong to P O S i x. 1. It should be understood that both S V R 4 and 4. 3 B S D provide compatibility to their earlier version of the function (eg, S V R 3. 2 pair 4. 3 B S D). For example, S V R 4 provides support for non-blocking I / O (O _ N O N B L O C K) in P O S i X Specifications and Traditional System V Method (O _ N D E L AY). This book will only use the function of P O S i x. 1, but will also mention which non-standard function it is replaced. Similar to this, S V R 3. 2 and 4. 3 B S D provide a reliable signaling mechanism in some way, and this method is different from P O S i x. 1 standard. Chapter 1 0 will only explain the signal mechanism of P O S i x. 1. 2.5 Restrictions There are many magic numbers and constants that are defined by implementation, with many of which have been written in the program, or determined by specific techniques. Due to the efforts of a large number of standardized work, several portable methods are used to determine the limitations of these illusion and implementation. This is very helpful in the portability of the software. The following three types of functions are required: • Compile time selection (whether the system supports job control). • Compile time limit (what is the maximum of short integer). • Runtime limit (how much is the maximum number of file names). The first two, compile time selection and restrictions can be defined in the header file. The program can contain these header files when compiling. However, runtime limits require that the process calls a function to obtain such a limit value. In addition, some limitations may be fixed in a given implementation (so it can be defined in a header file), and in another implementation may be variable (there is a run time function call). An example of this type limit is the maximum number of characters of the file name. System V Only the file name is allowed to have 1 4 characters due to historical reasons, while Berkeley's system will increase this to 2 5 5. S V R 4 allows us to indicate each created file system is a system V file system or a B S D file system, while each system has different restrictions. This is an instance of runtime limits, and the maximum length of the file name relies on the file system where the file is located. For example, the file name length limit in the root file system may be 1 4 characters, and the file name length limit in some other file system may be 2 5 5 characters. In order to solve these problems, three restrictions are provided: (1) Edit Time Selection and Restrictions (header files). (2) Do not be related to the runtime limit associated with the file or directory. (3) Operation time limits associated with files or directories. What makes things more complicated is that if a specific runtime limit does not change on a given system, it can be static in a header file, but if not defined in the header file. In the application, the application will be chapter 2 UNIX Standardization and Implementation 2 1 Download One of the three conf functions (we will explain them soon) to determine its runtime value. 2.5.1 ANSI C Restriction All restrictions defined by ANSI C are compilation time limits. The C standard restrictions defined in File are listed in Table 2 - 2. These constants are always defined in the header file and will not change in a given system. The third column lists the minimum values ​​acceptable by the ANSI C standard. This is used for a system with a total length of 1 6-bit, which is represented by 1.

Column 4 lists the values ​​of the current system having a total length of 3 2 bits, and 2 of the complement indication method. Note that there is no minimum value for the data type without the symbol, which should be 0. One difference we will encounter is whether the system provides a character value with symbol (S i g n e d) or without symbol (U N S I g n e d). As can be seen from column 4 in Table 2 - 2, the particular system uses symbol characters. From the table, it can be seen that C H A r _ m i n is equal to S c H a r _ m i n, C H a ​​r _ m a x is equal to S c H a r _ m a x. If the system uses without a symbolic character, C H a ​​r _ m i n is equal to 0, C H a ​​r _ m a x is equal to U C H a ​​r _ m a x. In the header file , there are similar sets of definitions for floating point data types. Another ANSI C constant we will encounter is Fopen _ max. This is the minimum of standard I / O streams that achieve the guarantee, which is defined in header file , whose minimum is 8. The S t R e a m _ m A x (if defined) in P O S i x. 1 should be the same value as F O P e n_m. ANSI C also defines constant T m p _ m a x in , the maximum number of unique file names generated by the T M P n a m function. About this constant will be more described in 5. 1 3. Table 2-2 The size of the model indicates the minimum acceptable value typical value char _ bit char bits 8 8C Har _ max char's maximum (see) 1 2 7C Har _ min char Minimum (see) -1 2 8S char _ max with symbol char to maximum 1 2 7 1 2 7S char _ min with symbol char Size -1 2 7 -1 2 8u char _ max without symbol char Maximum 2 5 5 2 5 5i NT _ Max Int Maximum 32 767 2 147 483 647i NT _ min int smallest - 32 767 -2 147 483 648U INT _ max without symbol INTs 65 535 4 294 967 295S HRT _ min Short Minimum-32 767 -32 768S HRT _ Max Short Maximum 32 767 32 767U SHRT _ MAX without Symbol SHORT 65 535 65 535L ONG _ MAX LONG Maximum value 2 147 483 647 2 147 483 647L ONG _ min LONG minimum -2 147 483 647 -2 147 483 648U long _ max without symbolless long 4 294 967 295 4 294 967 295M B _ LEN _ MAX a multi-byte character constant Maximum byte 1 12.5.2 POSIX Limits POSIX. 1 Define a lot of constants involving the operating system implementation restriction, unfortunately, this is one of the most confusing parts of POSIX. 1.

2 2 U N i x Environment Advanced programming Download which includes 3 3 limitations and constants, which are divided into the following eight categories: (1) unchanged minimum (1 3 constants in Table 2 - 3). (2) Unset value: s I z e _ m a x. (3) Running time cannot be increased: N g R o u p s _ m a x. (4) Runtime constant value (may be uncertain): arg_max, child_max, open_max, stream_m a x, t z n a m e _ m a x. (5) path name variable value (may be uncertain): link_max, max_canon, max_input, name_max, pat h _ m a x, and P i p e _ b u F. (6) Edit time symbol constant: _P o s i x _ s aved_ids, _posix_version and _ p o s i x _ j o b _C o N T R O L. (7) Perform time symbol constant: _posix_no_trunc, _posix_vdisable, and _p O s i x _c H o w n _ r e s T R i C T E D. (8) Constants that are no longer used: C L K _ T C K. In this 33 restrictions and constants, 1 5 must be defined, and the rest can be defined as a specific condition. In 2. 5. 4, when the Sysconf, PathConf, and F P A T H C O N f functions, we describe definable non-definition restrictions and constants (Articles 4-8). In Table 2 - 7, we summarize all limitations and constants. 1 3 constant minimal values ​​are shown in Table 2 - 3. Table 2-3 POSIX. 1 unchanged minimum name description value _ POSIX _ arg _ max exec "parameter length 4 0 9 6_ POSIX _ Child _ MAX Each actual user ID child process number 6_POSIX _ LINK _ _ MAX to a file connection number 8_POSIX _ MAX _ Canon terminal specification input queue bytes 2 5 5_ POSIX _ MAX _ INPUT terminal input queue free space 2 5 5_ POSIX _ name _ max file Number of bytes in the name 1 4_ POSIX _ NGROUPS _ MAX Each process simultaneous add group ID 0_ POSIX _ OPEN _ MAX Each process Open file number 1 6_ POSIX _ PATH _ MAX path name number 2 5 5_POSIX _ PIPE _ BUF Energy Write the number of bytes of the pipe 5 1 2_ POSIX _ SSIZE _ MAX can exist in the SSIZE _ T object value 32 767_ POSIX _ stream _ max a process can open the standard I / O train 8_ POSIX _ TZNAME _ MAX time zone number 3 These values ​​are constant - they do not change with the system. They specify these most stringent values. A implementation that complies with P O S i x. 1 should provide at least a large value. This is why they call them the minimum, although their names contain m a x. In addition, a portable application should not require a larger value. We will explain the meaning of each constant in the appropriate part of this book. Unfortunately, some of these unchanged minimal values ​​are too small in practical applications. For example, the number of files currently open at the same time of each process of U N i x system far exceeds 1 6, even in 1 978 V7, it also provides 2.

In addition, _ p o s i x _ PAT H _ m a x minimum is 2 5 5 is too small, and the path name may exceed this limit. This means that these two constants cannot be used when editing _ p o s i x _ o p e n _ m a x and _ p o s i x _ Pat H _ m a x as array length. Each of Table 2 - 3 has a related implementation value, which is composed of the name of the name in Table 2 - 3 to delete the prefix _ P o s i x _ after. (These 1 3 implementations are 2 ~ 5 items listed in this section: unchanged value, running, unchette Unix standardization and implementation 2 3 download can increase, the runtime constant value, And pathname variable value.) The problem is that all this 1 3 implementations do not make sure to define in the header file. The reason why a particular value may not be defined in this header is: The actual value of a given process may depend on the total amount of memory of the system. If they do not define them in the header file, they cannot be used as an array boundary when compiling. Therefore, P O s i x. 1 decide to provide three runtime functions for call: sysconf, pathconf, and F P A T H C O N f, use them to get actual implementation values ​​at runtime. However, there is a problem because certain values ​​are defined by P O s i x. 1 is defined as "Uncertain" (logically unlimited), which means that this value is not actually limited. For example, each process of S V R 4 opens the number of files in an infinitely unlimited, so o p e n x is considered uncertain in S V R 4. 2. Section 7 will also discuss the problem of uncertain runtime limitations. 2.5.3 XPG3 restrictions X P G 3 defines seven constants, which are always included in the header file. P O S i x. 1 will call them unchanged minimal values. They are listed in Table 2 - 4. Most of these values ​​involve messages. Table 2-4 XPG 3 unchanged minimum name Description minimum acceptable value Value NL _ argmax calls Printf and scanf maximum digital value 9 9N L _ LangMaxLANG environment variable Maximum number of bytes 1 4 1 4N L _ MSGMAX Maximum Number of Messages 3 2, 7 6 7 3 2, 7 6 7N L _ Nmax in N to 1 Map of Maximum Number 1N L _ SETMAX Maximum Collection 2 5 5 2 5 5N L _ TextMax Message string 2 5 5 2 5 5N ZERO Default Process Priority 2 0 2 0X PG 3 also defines the value PA SS _ max, as the maximum number of valid characters in the password (not included Termination character null), it may be included in . P O S i x. 1 The value of the runtime constant (may be uncertain) is called the runtime, and the minimum acceptable value is 8. The PA S_ M a X value can also be obtained with the S Y S c O N F function at runtime, which will be described in 2. 5. 4. 2.5.4 Sysconf, Pathconf and FPathConf Functions We have listed a variety of minimum values ​​that implement must support, but how can they find a limit value actually supported by a particular system? As mentioned earlier, some limit values ​​are compiled It is available, while others must be determined at runtime. We have also mentioned that some restrictions in a given system will not be changed, while others are associated with files and directories. Running time limits are taken by one of the three functions below.

#include long sysconf (int name); log pathconf (int filedes, int name); all functions return: If success is the corresponding value, if it is wrong - 1 (see) The difference between the last two functions is a path name as its parameters, and the other will take the file descriptor as a parameter. The n a m E parameters used in these three functions are listed in Table 2 - 5. The constant starting with the _ S c_ is used as the parameters of S Y S C O N f, and the constant starting in the _ P C_ is used as the parameters of P A T H C O N f or F P a T H C O N F. 2 4 U N i x Environment Advanced Programming Download Download for Parameters of Pathconf P A T H N A M E, the parameters of FPathConf have many restrictions. If any of the restrictions are not met, the result is undefined. (1) _PC_max_canon, _ p c _ m a x _ i n p U t and the files involved in _ p c _ V D I S A B L E must be terminal files. (2) The files involved in _PC_LINK_MAX can be files or directories. If it is a directory, the return value is used for the directory itself (not the file name item in the directory). (3) _PC_NAME_MAX and _ P C_ N o _ T r u N c must be a directory, and return values ​​for file names in this directory. (4) _PC_PAT H _ m a x must be a directory. When the specified directory is a working directory, the return value is the maximum length of the relative path name. (Unfortunately, this is not the actual maximum length we want to know, we will return to this issue in 2. 5. 7:) (5) _PC_PIPE_BUF must be Pipelines, FIFOs or directories. In the case of pipe or F I f O, the return value is the limit value of the pipe or F I f O involved. For directories, the return value is the limit value of any F I f O created in this directory. (6) _PC_Chown_RESTRICTED must be a file or directory. If it is a directory, the return value indicates whether this selection is applied to files in this directory.

Table 2-5 Restrictions on Sysconf, Pathconf and FPathConf and Name Parameter Limit Name Description Name Parameters Arg _ MAX, EXEC function parameters (bytes) _ SC _ arg _ ma Xc Hild _ max, every actual user ID Maximum process number _ sc _ child _ ma xclock ticks / second, such as clock, clock diameter _ SC _ CLK _ TC KN Groups _ max If the maximum number of IDs in each process _ SC _ ngroups _ ma Xo Pen _ MAX, the maximum number of records per process _ SC _ open _ ma XP ASS _ max, such as the maximum number of valid characters in the password _ SC _ pass _ ma Xs Tream _ max, such as the maximum standard I / O, every time every moment Most - such as _ sc _ stream _ max If the value is defined, the value must be the same as the maximum number of bytes in the same TZNAME _ MAX time zone name _ SC _ TZNAME _ MA X_ POSIX _ JOB _ Control If you specify whether to implement your job Control _ SC _ Job _ Contro L_ POSIX _ SAVED _ IDS If you specify whether to support save settings - User - ID and Save _ SC _ SAVED _ IDS Settings - Group - I D_ POSIX _ VERSION If you specify POSIX. 1 version SC _ VERSIO N_ XOpen _ Version, such as the XPG version (non-POSIX. 1) _ SC _ XOpen _ VERSIO NL INK _ MAX such as file connection number maximum _ PC _ link _ ma XM AX _ Canon is in a terminal specification input Queue's maximum number of bytes _ PC _ Max _ CANO NM AX _ INPUT such as terminal input queue available space bytes _ PC _ max _ invu TN AME _ max, such as file name (excluding NULL end compact) _ PC _ Name _ ma xp Ath _max Such as the maximum number of bytes in the relative path name (excluding NULL end compact) _ pc _ path _ ma XP IPE _ BUF, like atomic, write to a pipe, maximum number of bytes _ PC _ PIPE _ bu f_ POSIX _ Chown _ Restricted Indicates if you are restricted using Chown_ pc _ chown _ restrict D_ POSIX _ no _ trunc, if the path is long than Name _ max is generated error _ PC _ no _ trun c_ pOSIX _ vdisable if defined, terminal dedicated characters available This value prohibits _ PC _ vdisable we need to explain the different return values ​​of these three functions more detailed. (1) If n a m e is not a suitable constant in the 3rd column of Table 2 - 5, all three functions return - 1, and standardize Chapter 2 U N i x and implement 2 5 Download E R R O R Set to e i n va L.

(2) 1 2 Name and NAM E_ PC _ PIPE _ BUF may or return the value of the variable (return value ≥o), or return -1, indicating that this value is not sure, this is not Change the value of Errno. (3) The return value of _ S c _ C L K _ T C K is a clock tick of each second to use the return value of the T i m e s function (see 8.15). (4) The return value of the _ S c_ V e R s I O n is indicated by 4 digits and 2 digits, respectively, respectively, respectively, the year and month respectively. This may be or 1 9 8 8 0 8 L or 1 9 9 0 0 9 L, or the value of this standard a later version. (5) The return value of the _ S c_ x o p e n _ v e R s I O N indicates the X P g version of this system, whose current value is 3. (6) _SC_JOB_CONTROL and _ S C_ S AV E D _ I D S is two optional functions. The corresponding function is not supported if S Y S Y C O N f returns -1 (without changing e r R N o). These two functions can also be determined from header files at compile. (7) If the return value of the _ P C_ C HO W N _ R E S R I C T E D and _ P C_ N O _ T R U N C is -1 (not changed ER R N o), it means that this function is not supported for the specified P A T H n M e or F I L E D e S. (8) If the return value of _ P C_ V D I S A B L E is - 1 (does not change E R R N o), this function is not supported by the specified P A T H n M e or F I L E D e s. If this feature is supported, the return value is a character value (see Table 11 - 6) that is forbidden to enter a particular terminal input character. Example Program 2 - 1 Used to print all of these restrictions and process a limit that is not defined. Program 2-1 Print All S Y S C O N F and P A T H C O N F Value 2 6 U N i X Environment Advanced Programming Download We include two constants, which have been added to P O S i x. 1, but not part of IEEE STD.1003.1-1988. Table 2 - 6 shows the sample output of the program 2 - 1 on several different systems. We can understand in 4. 1 4, the SVR4 S5 file system is a traditional system V file system that can be retrosted to V7. U f s is an implementation of S V R 4 of the Berkeley Express File System.

Table 2-6 Configuration restrictions Limit SUNOS 4.1.1s VR 44. 3 BS DS5 FileSys UFS Filesysa RG _ Max 1 048 576 5 120 5 120 20 480C Hild _ max 1 3 3 3 0 3 0 4 0 per second clock Tick ​​6 0 1 0 0 0 0 0 0 6 0N Groups _ max 1 6 1 6 1 6 1 6o Pen _ MAX 6 4 6 4 6 4 6 4_POSIX _ Job _ Control 1 1 1 1_ POSIX _ Saved _ IDS 1 1 1 Undefined _ POSIX _ VERSION 198 808 198 808 198 808 198 808M AX _ Canon 2 5 6 2 5 6 2 5 6 2 5 5M AX _ Input 2 5 6 5 1 2 5 1 2 2 5 5_ POSIX _ VDISABLE 0 0 0 2 5 5L INK _ MAX 32 767 1 000 1 000 32 767 Chapter 2 UNIX Standardization and Implementation 2 7 Download Argv [1], _PC_Chown_RESTRICTED); (Continued) Limit SUNOS 4.1.1s VR 44. 3 BS DS5 FileSys UFS FileSysn AME_Max 2 5 5 1 4 2 5 5 2 5 5P Ath_max 1 024 1 024 1 024 1 024P IPE_BUF 4 096 5 120 5 120 5 1 2_POSIX_N _ Trunc 1 Unefained 1 1_ POSIX _ Chown _ Restricted 1 Undefined Undefined 12.5.5 FIPS 151-1 Requirements FIPS 151-1 (we have mentioned in 2. 2. 4) Due to the following functions, it is stricter than POSIX. 1 standard: • Require the following POSIX. 1 optional function: _posix_Job_Control, _POSIX_SAVED_I DS, _POSIX_NO_TRUNC, _POSIX_CHOWN_RESTRICTED and _ P O S i x _ V D i S A B L E. • The minimum value of ngroups_max is 8. • Group I D of the newly created file or directory should be set to Group I D it in its directory (4. 6). • After some data has been transmitted, if R E A D or W R I TE is interrupted by a captured signal, these functions should return the number of bytes already transmitted (1 0. 5 Section will discuss the interrupted system call). • Login S h e l L should define environment variable H o M E and L O g n M E. Because the US government has purchased a lot of computer systems, most P O S i X manufacturers will support these increased F i P s requirements. 2.5.6 Summary Summary We have explained many restrictions and illusion, some of which must be included in the header file, some optionally in the header file, other can be determined at runtime. Table 2 - 7 summarizes all of these constants in alphabetical sequence and to get various methods for they. The running time name starting with _ S c _ is the parameter of the S Y s c o n F, with the name of the _ P c _ starting the P A T H C O N f and the F function parameters, if it has a minimum, it is also listed in it. Note that 1 3 P O S i x in Table 2 - 3 is shown unchanged minimum values ​​in Table 2 - 7.

Table 2-7 Compile time and runtime limit summary compilation time constant name header file requirements No run time name minimum arg _ max optional _ SC _ arg _ max _ pOSIX _ arg _m ax = 4 0 9 6C HAR _ Bit requirements 8C Har _ max Requirement 1 2 7C HAR _ min Requirement 0c Hild_max optional _ SC _ child _max _ POSIX _ CHILD _ MAX = 6 Ticks per second _ SC _ CLK _ TC KF Open _ Max Requirement 8i NT _ Max Requirement 32 767i NT _ min requirements -32 767L Ink _ Max Optional_PC_Link_max_Posix_Link_M AX = 8L ONG _ MAX Requirements 2 147 483 6472 8 Unix Environment Advanced Programming Download (Continued) Compile Time Concentrans Number file requirements No running time name minimum long _ min Requirements -2 147 483 647M AX _ can optional _ PC _ MAX _ can _ POSIX _ MAX _ can = 2 55M AX_Input Optional_PC _ MAX _ INPUT _ POSIX _ MAX _ INPUT = 2 5 5M B _ LEN _ MAX Requirement Name_ Max Optional_PC_Name_max_POSIX_NAME_M AX = 1 4n Groups _ Max Requirements _SC_NGROTS_MAX _ POSIX _ NGROUPS _ MAX = 0N L _ argmax Requirement 9n L _ langmax Requirement 4N L _ msgmax Requirement 32 767N L _ nmax Require NL _ setMax requirements 2 5 5N L _ TextMax Requirement 2 5 5N ZERO Requirement 2 0O Pen _ Max

Optional _ SC _ Open _ MAX _ POSIX _ OPEN _M AX = 1 6P ASS _ Max optional _ SC _ pass _ max 8P Ath _ max optional _ PC _ PATH _ MAX _ POSIX _ PATH _M AX = 2 5 5p IPE _ BUF Optional_PC_Pipe_Buf_Posix_Pipe_Buf = 5 1 2S Char _ Max Requirement 1 2 7S Char_ MIN Requires -1 2 7S HRT _ MAX Requirement 32 767S HRT _ min Requirements -32 767S size _ max requirements _ POSIX _ SSIZE _M AX = 3 2, 7 6 7S Tream _ Max optional _ SC _ stream _ max _ POSIX _ stream _ max = 8t MP _ max Requirement 1 0, 0 0t Zname _ max Optional _ SC_TZNAME_MAX _ POSIX _ TZNAME _MAX = 3U char _ max Requirement 2 5 5 5U INT _ MAX Requirements 65 535U long _ max requirements 4 294 967 295u SHRT _ MAX requirements 6 5 535_ POSIX _ Chown _ Restricted Optional _ PC _ Chown _ Restricte D_ POSIX _ Job _ Control Optional _ SC _ Job _ Contro L_ POSIX _ NO _ Trunc Optional _ pc _ no _ trun c_ pOSIX _ SAVED _ IDS optional _ SC _ SAVED _ ID S_ POSIX _ VDISABLE Optional_PC _ Vdisabl E_ POSIX _ VERSION Requirement_ SC _ VERSIO N_ XOpen _ Version

Requirements _ SC _ XOpen _ Versio N2.5.9 Undeterified Runtime Limits We have mentioned that some values ​​in Table 2 - 7 may be undefined, these values ​​are marked in the third column (Optional) The name is included in the name, or pipe _ buf. The problem we encountered is if these values ​​are not defined in the header file , then we can't use them when compiling. However, if their values ​​are undetermined, they may also be undefined at runtime. Let us observe two special examples - assign a memory for a path name and the number of decision file descriptors. Chapter 2 UNIX Standardization and Implementation 2 9 Download 1. Path Name Many Programs Need to Assign a memory for the path name, in general, the memory is allocated, and various magic numbers are used (where few is correct As an array length: 2 5 6, 5 1 2, 1 0 2 4 or standard I / O constant bufsiz. 4. 3 B S D Header The constant M a x Pat H L e n is the correct value, but there are many 4. 3 B S D application does not use it. P O s i x. 1 Try to use PAT H _ M a X value to help us, but if this value is uncertain, then it is still unheeditive. Program 2 - 2 is a full book that will use a function that dynamically allocates a memory for the path name. If constant PAT H _ M A x is defined in , there is no problem, if not, the P a T H C O N f is required. Because the return value of P A T H C O N f is regarding the first parameter as a relative path name based on the working directory. So specify the root as the first parameter and add the obtained return value to 1 as the result value. If P A t h c o n f indicates that PAT H _ m a x is uncertain, then we have to guess a certain value. The 1 when M a L O c is called to add N u L characters at the end (Pat H _ m a x does not consider it). The correct way to handle uncertain results is related to how to use allocated storage. For example, if we call allocation space for g e t c w D (return to the absolute path name of the current working directory, see 4. 2 2), and the assigned space is too small, then return an error, E R R N o is set to E R a N g E. The R E A L O c can then be called to increase the allocation space (see Section 8 and Exercise 4. 1 8) and try again. Constantly repeat this operation until G e t c w d is successfully executed. Program 2-2 Dynamically allocate space 3 0 UNIX Environment Advanced programming download 2. The maximum opening file is in a common code sequence in the wizard process (which is running in the background, not connected to the terminal). Close all open files. Some of the following procedures are code sequences: #include for (i = 0; i header file Define constant nofile. Other programs use certain versions to provide constants as the upper limit _ n f i l E. Some procedures are directly set to 2 0.

We want to use POSIX. 1 Open _ max to determine this value to improve portability, but if this value is uncertain, there is still a problem if we use the following code #include for (i = 0 i

If we only want to use P O s i x. 1 definition, then you can set the first line of the source file to: #define _posix_source 1 another function test macro is: _ _STDC_ _, which is automatically defined by complication of the ANSI C standard. This allows us to write an agent that ANSI C compiler and non-ANSI C compiler can compile. For example, a header file may be: #ifdef _ std c__void * myfunc (const char *, int); # els evphot); # Endif This can play the strength of ANSI C prototype function, pay attention to starting and The two consecutive underscons at the end are often printed into a long line (as in one of the above sample source code). 2.7 Basic System Data Type History, some UNIX variables have been associated with certain C data types, for example, the historical master, the secondary device number is stored in a 1 6-bit short integer, and 8 represent the main device number. The other 8 indicates the secondary device number. However, many larger systems need to use more than 2 5 6 values ​​to represent their device number, so there is a need for different techniques. (Indeed, SVR 4 represents device number with 3 2 digits: 1 4 digits for primary device number, 1 8 digits for the secondary device number.) Header file defines some and implementation related Data types, they are called basic system data classes 3 2 UNIX Environment Advanced programming download type (Primitive System Data Type). There are a lot of this data type to define in other header files. These data types in the header file are defined by the T y P E D e F facility of C. Most of them are ending in _T. The basic system data types of this book will be listed in Table 2 - 8.

Table 2-8 Basic System Data Type Type Description CADDR_T Memory Address (1 2. 9) Clock_ T Tissue Counter (Process Time) (1. 1 0) COMP_T Compressed Clock Tick (8. 1 3 section) DEV _ T device number (main sum) (4. 2 3) FD _ set file descriptor set (1 2. 5. 1) fpos _ T file location (5. 1 0) GID _ T numeric group I di NO _ Ti node number (4. 1 4) MODE _ T file type, file creation mode (4. 5) N 1 ink _ T directory item connection count (4. 1 0) OFF _ T file length and displacement (with symbol) (Lseek, 3.6) PID _ T process ID and process group ID (with symbol) (8. 2 and 9. 4) PTRDIFF _ T two pointers Results (with symbol) R 1 IM _ T resource limit (7.11) SIG _ Atomic _ T can access data type (1 0. 1 5) SIGSET _ T signal set (1 0. 11 section) SIZE _ T object (such as string) length (without symbol) (3. 7) SSIZE _ T Return to byte count (with symbol) (READ, WRITE, 3.7) Time _ T The second counter (1. 1 0) UID _ T Value User I DW Char _ T can indicate that all different character codes define these data types, no longer need to consider the system when compiling Differential implementation details, in this book involve these data types, we will explain why they use them. 2.8 The conflict between the standards is considerable, and these different standards are quite good. But we also pay attention to the difference between them, especially the difference between the ANSI C standard and P O S i x. 1. (Because XPG 3 is an older is being revised standard, FIPS is a more stringent POSIX. 1.) ANSI C defines a function clock, which returns the CPU time used by the process, the return value is a clock _ T type value. In order to convert this value into seconds, divide it in the header file defined in the C L O c k K, PER, PE... P O s i x. 1 Define the function T I m e s, which returns the C P U time of its caller and all its terminator processes, and all of these values ​​are C L O c k _ T type values. IEEE STD.1003.1-1988 The symbol C L K _ T C K is defined as a drop of tick per second, and the above C L O c k _ T value is measured in this measure. In the 1990 POSIX.1 standard, it will be used to use the S Y s c o n f function to obtain a tick per second, and it is used for the return value of the T i m e s function.

转载请注明原文地址:https://www.9cbs.com/read-32918.html

New Post(0)