call, because there is no cache mechanism, therefore, 25224 million system calls will be executed accordingly, and million function calls will be executed in fgetc. However, due to the caching mechanism, only system calls will be executed. We know that the overhead of system calls is much greater than that of function calls.
7. Summary
The standard I/O functio
following :#include unit16_t htons (unit16_t host16bitvalue);unit32_t htons (unit32_t host32bitvalue);/* Returns the value of the network byte order */unit16_t Ntohs (unit16_t net16bitvalue);unit32_t Ntohs (unit32_t net32bitvalue); /* Returns the host byte order value */s should be treated as a 16-bit value (for example, TCP or Udpport). Consider L as a 32-bit value (e.g. IPV4 address);In addition to the byte order problem for each field in the protocol header, there is a byte order problem wit
Recently in the "UNIX Network Programming" (abbreviated UNP) and "Linux program Design", for the first time in UNP to get the example of the server, practice always a little headache, Because the author contains all of the declarations in the unp.h, resulting in the subsequent writing of the code will be dependent on the header file, and learn not to call the corresponding function, which should contain the
Unix programming FAQ v0.10
I accidentally found a Unix programming FAQ. Fortunately, it has been translated into a Chinese version! Although old, it is still useful.Provided by linuxforum.net. Thank you for your contribution.
The following is the chapter directory. The original Article is still on linuxforum.net, so it
UNIX advanced environment programming (7) standard I/O function library and I/O function library
1 Binary IO (Binary IO)
In the previous article, we learned about character-by-character read/write and row-by-row read/write functions.
If we want to read and write binary files and want to read and write the entire file, although these two functions can be implemented, they will obviously be troublesome and th
already exists:
If the size of the new value is smaller or equivalent than the value already exists, overwrite the old value directly;
If the new value is larger than the value already exists, then we must make a new memory space for the new value malloc, copy the new value into that memory, and replace the pointer to the old value with a pointer to the new value.
If we add an environment variable:
First we need to call malloc to allocate space for the string n
also contains the I node (I-node, index node) of the file, which is used to read the open file from disk to memory. The I node contains the owner of the file, the length of the file, and a pointer to the location of the file's actual data block on disk. (The Unix file system has more information about the I node.) In addition, Linux does not use the V node, but instead employs a file
through tcpdump see the following situation:that is, the data in the process of transmission in fact the error (the above example is the Port unreachable error, which is an ICMP message), but the client program is not aware of the error occurred, still blocking the recvfrom waiting for the data to return, so it is not conducive to us to quickly locate the error.So is there any way to get the wrong message?-An error message can be obtained using a connected UDP socket interface.UNIX Network
, create a login process for each user to process the logon process for each user. if the user is successfully registered, the login process creates another shell process for the user.
Each shell process waits for the user to enter the command. shell executes the shell interpreter, analyzes the received commands, and then creates a process to execute the command. the process that executes the command can continue to create the process as needed. after a command is executed, return to the shell
queuing related knowledge
#include See the UNIX Advanced Environment Programming 286 page, which explains why Sigsuspend is present, the most important of which is its atomic operation (first recover the signal screen word and then make the process hibernate (accurately suspend)) the signal screen word for the process is set to the Sigmask point value. Return conditional signal occurs, and the signal
call...Error #133: Unknown error 133Error #134: Unknown error 134lienhua34:demo$3. multi-thread Extension
In a thread-supporting environment, multiple threads share the process address space. Each thread has its own local errno to prevent one thread from interfering with another thread.
The strerror () function is not thread-safe. This function stores the string corresponding to errnum in a static buffer and returns the pointer to the buffer. When another thread calls strerror (), it will reset
1 Introduction
I/O (unbuffered I/O) without a buffer refers to a system call in the kernel called by each read or write, these I/O without a buffer are not components of Iso c.
2. file descriptor
Each opened file is referenced by a file descriptor, which is a non-negative integer. The file descriptor returned by the open and create functions is used by read write and close.
In UNIX, file descriptor 0 is as
Apue. h is a file written by the author. It contains common header files and is not provided by the system. This includes common header files and definitions of error handling functions. It is really convenient to use.
The content of apue. h is as follows:
#ifndef _APUE_H #define _APUE_H #define _XOPEN_SOURCE 600 /* Single UNIX Specification, Version 3 */ #include
To use it, perform the followi
Unix shell programming (1)
Unix only recognizes three basic file types: common files, directory files, and special files.Normal file: any file on the system that contains data, test, program instructions, or just about anything else.
Number of words in the Statistical File: WC commandFor example:[Root @ localhost test]
at system startup, or if you can shut down these programs correctly when the system restarts, you need to create a run-level script.Run levelDetermine the current runlevel: Who-r (Linux system: RunLevel The first value is the previous runlevel of the system, and the second value is the current runlevel.) )InittabThe i
UNIX advanced environment programming (12) Process Relationships-terminal logon Process, Process group, Session, unixrelationships
In the previous chapter, we learned that processes are associated with each other:
Each process has a parent process;
When a child process exits, the parent process can perceive and obtain the exit status of the child process.
In this chapter, we will understand:
More deta
Most of the UNIX errors return a negative integer or error code, and 0 is the error code.1. A file descriptor will be returned when each file is opened2.unix standard input and output error code file descriptors are replaced with constant Stdin_fileno,stdout_fileno,strerr_fileno (in unistd.h file) in 0 1 2,posix.1 respectively3.Open function Use (do not remember, write more, more practice, just remember, do
Preface
This section describes how to use basic Linux/Unix functions and poll calls to compile a complete server and client example that can be run on Linux (UBUNTU) and Unix (FreeBSD, the functions of the client and server are as follows:
The client reads a row from the standard input and sends it to the server.
The server reads a row from the network and then outputs the row to the client.
The cli
Linux programming is a very good book with comprehensive content and detailed explanations of the examples given. In addition, it is explained through a small project: the first is to use shell for programming, and then gradually improve, use C language for implementation, use the ncurses library for implementation, and use the DBM database instead, use a MySQL d
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.