21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

70 <strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>‘/dev/fd/N’The file associated with file descriptor N. Such a file must be opened by theprogram initiating the awk execution (typically the shell). Unless special painsare taken in the shell from which gawk is invoked, only descriptors 0, 1, and 2are available.The file names ‘/dev/stdin’, ‘/dev/stdout’, and ‘/dev/stderr’ are aliases for‘/dev/fd/0’, ‘/dev/fd/1’, and ‘/dev/fd/2’, respectively. However, they are moreself-explanatory. The proper way to write an error message in a gawk program is to use‘/dev/stderr’, like this:print "Serious error detected!" > "/dev/stderr"Note the use of quotes around the file name. Like any other redirection, the value mustbe a string. It is a common error to omit the quotes, which leads to confusing results.4.7.2 Special Files for Process-Related Informationgawk also provides special file names that give access to information about the running gawkprocess. Each of these “files” provides a single record of information. To read them morethan once, they must first be closed with the close function (see Section 4.8 [Closing Inputand Output Redirections], page 71). The file names are:‘/dev/pid’Reading this file returns the process ID of the current process, in decimal form,terminated with a newline.‘/dev/ppid’Reading this file returns the parent process ID of the current process, in decimalform, terminated with a newline.‘/dev/pgrpid’Reading this file returns the process group ID of the current process, in decimalform, terminated with a newline.‘/dev/user’Reading this file returns a single record terminated with a newline. The fieldsare separated with spaces. The fields represent the following information:$1 The return value of the getuid system call (the real user ID number).$2 The return value of the geteuid system call (the effective user IDnumber).$3 The return value of the getgid system call (the real group IDnumber).$4 The return value of the getegid system call (the effective group IDnumber).If there are any additional fields, they are the group IDs returned by thegetgroups system call. (Multiple groups may not be supported on all systems.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!