Book contents
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
D - Thread-Safe and Process - Safe Reporting and Logging Functions
Published online by Cambridge University Press: 13 January 2010
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
Summary
Here we present the reporting and logging functions referred to in the text of the book on several occasions, especially in Chapter 11. This particular example is POSIX 1 compliant.
All functions comply with the same syntax and semantics for arguments as the printf() function (i.e., variable number of standard arguments). Functions named in all lowercase (sys_exit(), sys__exit(), msg(), msg_exit(), msg__exit(), and msg()) write their messages to the standard output (i.e., to the screen of the terminal under normal circumstances), whereas functions whose names begin with an uppercase letter (Sys_exit(), Sys__exit(), Sys(), Msg_exit(), Msg__exit(), and Msg()) write into a single log file.
The functions sys(), msg(), Sys(), and Msg() save on entry the current signal mask, block all signals, and than write the message - hence they cannot be “interrupted”. On return, they reinstate the original signal mask.
The functions sys_exit(), sys__exit(), msg_exit(), msg__exit(), Sys_exit(), Sys__exit(), Msg_exit(), and Msg__exit() block all signals on entry. They do not save the original signal mask because they do not return; these functions exit using the system call exit(1) (functions sys_exit(), msg_exit(), Sys_exit(), and Msg_exit()) or _exit(1) (functions sys__exit(), msg__exit(), Sys__exit(), and Msg__exit()).
Functions msg_exit(), msg__exit(), msg(), Msg_exit(), Msg__exit(), and Msg() just write the requested message and either return (msg() and Msg()) or exit using exit(1) (msg_exit() and Msg_exit()) or _exit(1) (msg__exit() and Msg__exit()).
Functions sys_exit(), sys__exit(), sys(), Sys_exit(), Sys__exit(), and Sys() write a more elaborate system error message (together with the requested message) describing the error that happened based on errno.
- Type
- Chapter
- Information
- Memory as a Programming Concept in C and C++ , pp. 234 - 238Publisher: Cambridge University PressPrint publication year: 2003