• A shell is a special application (command line interpreter) that provides an interface to run other applications.
  • What does POSIX prescribe for operating systems
  • Each process has a working directory (also known as the current directory) from which relative paths are explained.
  • Ctrl+D is the end-of-file character
  • Read Specifies the number of bytes to read. Fgets reads a row
  • Three process control functions: fork exec WaitPID. Waitpid the parent waits for the child to terminate and knows when the child will terminate. The system function is outsourced by exec.
  • Execlp requires arguments terminated with null, not newline characters
  • A thread ID is valid only within the process it belongs to, and meaningless in another process. You can use the thread ID to reference the corresponding thread.
  • A user can belong to up to 16 groups
  • CTRL + C break key, CTRL +\ exit key, equivalent to the kill function. Kill (PID, SIGTERM) sends a signal to another process. The owner of the process must initiate the signal.
  • (GDB)set follow-fork-mode child to enter the pid==0 statement block. The breakpoint cannot be set after the child process exits. GDB information is lost. In this case, run may start the grandson process instead of the parent process.
  • Fork copies code from fork to end of function
  • Calendar time: the number of seconds since 1970. The time_t type is used to hold this time.
  • Process time: CPU time. The clock_t type is used to store this time.
  • System CPU time is the time it takes a process to execute a kernel program. The time to execute user instructions is user CPU time. The sum of the two is CPU time. Clock time, wall clock time, is the total amount of time a process runs, and is related to the number of processes. Time ls [ls can be changed to any program name] check the time.
  • Clock_t times(struct TMS * buf)
  • Library functions do not necessarily call system calls. Applications can call system calls either directly or through C library functions.
  • The ISO C standard has 24 header files (including stdlib.h,stdio.h).
  • Interfaces are protocols.
  • Many programs need to allocate storage for paths
  • Daemon: A process that runs in the background and is not connected to a terminal.
  • File – or directory-independent options are identified with sysconf, file – or directory-related options are identified with pathconf,fpathconf.
  • Most file I/O on Unix systems requires only five functions: Open Close Read Write Lseek, which is unbuffered I/O. Unbuffered refers to a system call that read Write calls to the kernel. Unbuffered IO is not part of ISO C, it is part of POSIX.
  • As far as the kernel is concerned, all open files are referred to by file descriptors (non-negative integers). 0, 1, 2 are descriptors for input and output errors, respectively. The file descriptor ranges from 0 to OPEN_MAX(indicating that each process can open OPEN_MAX files).
  • The open function: Int a count returns the smallest did not use the file descriptor numerical 】 = open (tmpPtr – > _fileName [name], O_RDWR | read, write, open 】 【 O_CREAT, if there is no create 】 【 0666) cooperate with O_CREATE specify a new file access 】 【;
  • close(fileId); Closing a file releases all record locks that the process has placed on the file. The kernel closes its open files automatically when the process terminates.
  • Return file offset =lseek(fileId,offset every open file has an offset for the current file, default 0 unless O_APPEND is specified) SEEK_SET
  • Lseek returns -1 indicating that the file descriptor corresponds to a pipe, FIFO, or network socket. Some devices allow negative offsets.
  • Od -c File name [-c indicates that the file is printed in character] ls -ls Displays the number of disk blocks that the file occupies
  • NRead = read(flag_fd (file descriptor), buffer (number of bytes read at a time), length (number of bytes read at a time)
  • Int bytes_write (return bytes written) = write(fileHandle, PTR,writeSize)
  • Measuring file reads and writes may be inaccurate after the first time due to caching mechanisms.
  • Each process has an open file descriptor table -> file table (current file offset) -> V node information
  • There may be multiple file descriptors pointing to the same file entry, and multiple file entries pointing to a V-node table. Multiple processes have no problem reading the same file, but have problems writing the same file -> atomic operations.
  • Open uses O_CREAT and O_EXCL to combine test and create into a single atomic operation. An atomic operation is a multi-step operation that either performs all of the steps or none at all.
  • Lseek then write cannot be an atomic operation. The kernel can suspend processes between two functions.
  • pread(… , off_t offset) pwrite(… , off_t offset) is equivalent to sequential calls to lseek and read. The difference is that sequential calls cannot be interrupted and file Pointers cannot be updated
  • Each time you open a file in O_APPEND mode, the offset of the file is automatically moved to the end of the file.
  • The new file descriptor = Dup (int Filedes) dup2(int Filedes [copied],int filedes2 [specified value]) copies the existing file descriptor and shares the same file entry as parameter Filedes. fcntl(..) File descriptors can also be copied.
  • Sync queues block buffers into write queues, without actually writing to disk. Fsync works on a single file and updates the properties when it returns after writing to disk. Fdatasync affects only the data part of the file.
  • fcntl(..) The return value is command dependent and can return file status, file descriptor. You can modify the file status.
  • 5<>temp opens the file for reading and writing at file descriptor 5.
  • Terminal I/O is the most used aspect of IOCTL.
  • Digit1 > &digit2 indicates that you want to redirect digit1 to the same file as descriptor 2.
  • The shell processes commands from left to right
  • Struct stat sA; struct stat sA; Int retA = stat(filenamea.c_str (), &sa (stat will fill sA)); Ls -l is the stat(…) used. function
  • lstat(…) The enhancement is to detect symlinks
  • The file type information is contained in the ST_mode member of the STAT structure and has the following types.

Plain file [A file that contains some kind of data, whether text or binary makes no difference to the kernel, and its contents are interpreted by the application that processes the file. Exception: Binary executable file to comply with the kernel understand the unified format of the catalog file (containing the name of the other files and pointer to information related to these files 】 block device file on the disk, provided with a buffer access 】 character device file (keyboard, providing access to equipment without buffer 】 FIFO and pipe file, The vertical lines in the shell | for interprocess communication socket 】 【 this file is used to process the network communication between, also can be used for a machine process of network communication between 】 a symbolic link “this type of file to another file”

  • Interprocess communication (IPC) objects are also represented as files: message queues, semaphores, shared storage objects.
  • When executing a program, exec(…) A valid user ID and a valid group ID are saved. Usually valid ID== actual ID.
  • When the valid user ID of a file is set to the file owner ID, the process has super privileges even if it is executed by a common user if the owner is root.
  • File access: The first rule is that when we open a file with a name, we should have execute access to every directory that contains that name, including the current working directory (./) it may imply. You have appropriate permissions on files, depending on how you open them.
  • Read permission on a directory gives us a list of all file names for that directory. The execute permission on the directory allows us to search for a particular filename through the directory, that is, the search directory.
  • To create a file, you must have write and execute permissions on the directory. To delete a file, you need to have write and executable permissions on the directory (actually reduce the number of connections to the file I node, the file itself still exists), and do not need to have read and write permissions on the file itself (delete the file itself did not read or write).
  • The user ID for the new file is set to a valid user ID for the process. The group ID of the new file can be: 1. The valid group ID of the process. 2. Group ID of the directory where it resides.
  • Access (Pathname, mode) Tests the access permission based on the actual user ID and group ID. Only root can chown.
  • umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); Set the file mode of the process to create mask word

Creat (” bar “, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) has been running the above two lines run results rw — — — — — — — the bar chmod (” bar “, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) fchmod (fildes, mod) run results – rw – r – r – bar

  • – rw-rwsrw -s Indicates that the group ID [valid user ID and group ID] bit is set. The valid user ID becomes the ID of the file owner. At the same time, the group execution bit is not set.
  • Linux swap == Windows virtual memory
  • Chmod a+t directory set sticky bit
  • Stick bit: A copy of the executable program body is kept in the swap area. Directory set stick bit, only have write permission on directory plus 1. 2. Own a directory; 3. You can delete or rename files in the root directory only if there are three types.
  • Chown fchown lchown Changes the file user ID
  • Truncate (Pathnane, length) FTRUNCate (Filedes, length) truncate the file or create a void
  • The disk can be divided into partitions, with different partitions having different file systems.
  • Directory entry [directory/file name] -> I node -> Actual data block. Multiple directory entries can point to the same I node. For example, if the soft connection and directory itself point to the same piece of data, they should point to the same I node. Mv Changes only the directory name but does not move the actual data.
  • Link (existPath, newPath) Creates a new directory entry and increases the number of links; Unlink (pathname) Deletes a directory entry and reduces the number of file links referenced by pathname by 1. Files are not visible after directory entries are deleted, but they may still occupy disk space until they are deleted by the kernel.
  • ./a.out & Indicates background running
  • If both the number of open processes and the number of links are 0, the kernel deletes the file.
  • Remove (pathname) Unlinks a directory or file. rename(oldname, newname)
  • The relationship between a normal directory entry and the file itself is a hard link that points directly to the I node of the file. A symbolic link is an indirect pointer to a file across different file systems. Note whether the function follows symbolic links.
  • Symlink (ActualPath, Sympath) creates symbolic links. Readlink (pathName, buf, bufsize) opens the link itself and reads the name in the link.
  • By default, ls -lt sorts by file modification time, -u by access time, and -c by status change time. Utime (pathname, times) Changes the file access and change time.
  • Mkdir (pathname, mode) creates a new empty directory. Rmdir (pathname) Deletes an empty directory.
  • DIR *opendir(pathname) struct dirent *readdir(DIR *dp) chdir(…) The current working directory is an attribute of the process, chdir only affects the process itself. Fchdir (…) getcwd(…) Get the full absolute path
  • Standard I/O library ISO C standard file operations around file descriptors, also known as around streams. When we open or create a file with standard IO, we have a stream associated with the file. Standard IO eventually calls read,write.
  • The FILE structure contains: FILE descriptor, buffer pointer, buffer length, current buffer bytes, and error flags. The FILE pointer is FILE*
  • The standard input/output file Pointers are stdin,stdout,stderr. IO libraries provide buffering to reduce the number of calls using read and write. Standard IO functions usually call malloc to get buffers.
  • Setbuf (FILE*, buf, mode,size) changes the buffer type. Fflus (FILE *fp) This function causes all unwritten data from the stream to be passed to the kernel.
  • FILE * FDopen (Filedes, type) associates existing FILE descriptors with streams.
  • FILE *freopen(pathName, type, FILE * RESTRICT FP) Opens a FILE on a specified stream, or closes the stream if it is already open. Generally used to open a specified file into a predefined stream: input, output, error.
  • FILE *fopen(pathname, type [r+b, plus sign for read and write]) opens a specified FILE,b distinguishes text from binary and is useless for Unix. The cache is open
  • Int fclose(FILE *fp) closes an open stream.
  • Read and write structure fread fwrite
  • Fgets fputs one line at a time
  • One character at a time geTC (FILE* fp) fgeTC (FILE* fp) getChar (void) Getchar is equivalent to geTC (stdin). Ferror (FILE *fp) feof(FILE *fp) void clearErr (FILE *fp)
  • Int ungetc(int c, FILE *fp) presses the character back into the stream.
  • Putc (int c, FILE*) fputc(int c, FILE*) putchar(int c)
  • Calling functions takes longer than calling macros; A system call takes more time than a normal function call.
  • Char char for one line of IO at a timefgets(buf,n,FILE) reads from the specified stream. Char * gets(buf) reads from standard input. Output: fputs (str, FILE) puts(*str)
  • Binary IO: size_t fwrite(&struct[2], sizeof(struct), 4, FILE* fp) writes elements 2-5 of an array to a FILE
  • fread(..) It can only process data on a unified system, but not when heterogeneous systems are interconnected through a network. The exchange of binary data between different systems requires a more advanced protocol.
  • Ftell (FILE*) fseek(FILE*, offset, whence【SEEK_SET】) rewind(FILE*) fgetpos(..) ftell(FILE*) fseek(FILE*, offset, whence【SEEK_SET】) rewind(FILE*) fgetpos(..) fsetpos(…) The file descriptor is lseek
  • Int fileno(FILE* fp) gets the FILE descriptor, FILE* tmpfile(void) creates a temporary FILE
  • $TMPDIR=.. ./a.out Specifies environment variables before the program name
  • int printf(format,…) Writes formatted data to standard output. vprintf(format, va_list arg) vfprintf(… ,va_list arg) vsprintF vSNPrintf variable parameter list (…) Into arg
  • int fprintf(FILE* fp, format, …) Write to the specified stream
  • Int sprintf(buf, format) writes the formatted string to the array buf, automatically adding null bytes to the end of the array
  • int snprintf(buf, size_t n,format, …) Much like sprintf, n specifies the buffer length, which is discarded to avoid overflows
  • int scanf(format, …) Sscanf (cmdline [source], “%s %s”, opt[0], opt[1])
  • int fscanf(FILE *fp, format, …)
  • int sscanf(buf, format, …) Vscanf (format, va_list arg), etc
  • struct passwd getpwnam(const charName) gets the password file entry
  • Struct TM a form of year, month and day used to hold time.
  • Struct timeVal *res (struct timeval *res, NULL
  • Time_t time(time_t* calptr) Returns the current time. Calptr is not empty.
  • Struct tm* localtime(const time_t* PTR) The difference is that it converts calendar time to local time zone time and GMTime to international standard time.
  • Time_t mktime(struct tm* PTR) convert local time to time_t (struct tm* PTR)
  • char Asctime (struct tm) returns a pointer to the year month day string. charCtime (time_t * PRT) returns a pointer to the calendar time.
  • size_t strftime(…) Controls the time string by format
  • Timeval specifies seconds and microseconds, timespec specifies seconds and nanoseconds
  • Normally terminates a program: Exit () contains the closing stream operation by default. In main, exit(0) is equivalent to return(0).
  • Functions registered by int atexit(void (*func)(void)) are called in reverse order by exit.
  • The only way for the kernel to execute a program is exec. The only way for a process to terminate voluntarily is exit, explicit or implicit. An involuntary need gives a signal to terminate.
  • Extern char **environ environment pointer getenv putenv Accesses specific environment variables
  • The symbol table segment, debug information segment, and dynamic shared library link table segment of A. out are not loaded into the program image executed by the process. Size a.out Specifies the length of the report body segment, data segment, and BSS segment
  • Cc-static hello1.c prevents the use of shared libraries. Cc uses shared libraries by default
  • Void * malloc(size_t size) The initial value of the storage area is uncertain
  • Void * calloc(size_t nobj, size_t size) allocates storage for a specified number of objects of a specified length, initialized to 0
  • Void * realloc(void* PTR, size_t newsize) changes the previous length.
  • void free(void* ptr)
  • Goto statements cannot span functions, and setjump Longjmp can handle errors in nested calls. Int setjmp(jmp_buf env), int longjmp(env,8)
  • “Str1” “str2” is equivalent to “str1str2”. Allocating buffers to IO libraries should be globally static or dynamic ALLOC allocation.
  • Compiler optimization, it can sometimes take some value, direct access from the register, rather than from memory access, this optimization in a single-threaded program there is no problem, but in multi-threaded programs, is due to multiple threads to run concurrently, it is possible to a thread to a public variables have changed, At this time, the value of the register in the other threads has been outdated, but the thread itself is not aware of it, thinking that it has not changed, still get from the register, resulting in the program will run undefined behavior.
  • Automatic variables do not want to be rolled back and can be defined as the volatite property. The volatile property tells the compiler not to optimize, which would change the value elsewhere, and the optimization might keep the variable in the register.
  • Int getrlimit(int resource, struct rlimit * RLPTR) setrLimit Ulimit in shell.
  • Getpid getppId getuid geteuid getgid getegid
  • Pid_t fork(void) fork returns clone twice, parent returns child, child returns 0. The parent process executes the code after fork, sharing the body, not the data, but the file table and the I node. Copy-on-write Copy is copied while writing and shared when read only.
  • Vfork runs in the parent’s space until the child calls exec or exit, after which the parent continues to run.
  • The standard IO library printf is buffered. Standard output to the terminal is line buffered, otherwise full buffered. Direction-to-file is fully buffered
  • Signals can be generated by the process itself [abort], by other processes [kill(piDID, SIG)], or by the kernel.
  • A child whose parent terminates prematurely is adopted by the init process. The kernel stores a certain amount of information for each terminated child process, and the parent process gets this information using wait or WaitPID.
  • A long-running process forks many child processes, and many dead processes occur unless you wait manually.
  • Pid_t wait(int* statloc) pid_t waitPID (pid_t pid, int* statloc, int options) pid_t wait(pid_t pid, int* statloc, int options) If you call WAIT on SIGCHLD, you can return immediately. If you call WAIT at any time, it may block until one of the child processes terminates.
  • Wait3 Wait4 has one more feature than waitPID in that the last parameter returns a summary of resource usage by all child processes.
  • Race condition: Multiple processes process shared data, and the result of the data depends on the order in which it is processed. While (getppid()! = 1) sleep(1); 1 is the ID of the init process. A value of 1 means that the parent process is dead and taken over by init.
  • Exec does not create a new process, and the process ID remains unchanged. Exec simply replaces the body, data, queue, and stack of the current process with a new program. execl execv execle execve execlp execvp
  • All.c files look for the instruction $grep abort./ for the string abort/.c
  • At any time, you can call int setuid(uid_t uid) to do two things: valid user ID= actual user ID; Valid user ID= saved set user ID (exec copy valid user ID) . Set the user ID of the program, fork, before the exec to normal permissions, should not use the system function.
  • #suspend $FG job control
  • Fork ->exec(awk)->wait
  • Char * getLogin (void) Obtains the login name. Find the user login name getPwuid (getuid()) to run the program
  • Network login The telnetd process fork. The parent is responsible for network connection communication, the child executes login, and the father and son are connected through a pseudo terminal.
  • A process group is a collection of one or more processes. Getpgid setpgid Sets the group ID of the specified process or calling process.
  • A session is a collection of one or more process groups. The process calls pid_t setsid(void) to establish a new session. The process is the first process, the group leader, and all control terminals are disconnected. Pid_t getSID (pid_t pid) Returns the process group ID of the first session process.
  • SecureCRT is the terminal, corresponding to the foreground process group [the process associated with the terminal (which is also the file descriptor)], the control process group [shell], the background process group [& running it in the background], and together is the session.
  • A job is a collection of several processes, usually a pipeline of one process. Vi. The main front desk to start a homework 】 【 pr c *. C | LPR & | make all & 【 background launched two assignments, two jobs calls all processes of the background 】
  • The terminal driver generates signals that affect the foreground process group: interrupt character CTRL +C Exit character CTRL +\ Suspend character CTRL +Z. The background job can be paused with a signal, fg %1 turns job 1 into a foreground job
  • A process belongs to a process group, which belongs to a session that may or may not control the terminal. The foreground process group ID is an attribute of the terminal, not of the process.
  • The last process of the pipe is a child of the shell, and all other commands that execute the pipe are children of the last process. If front-end process group ID==sessionID, it indicates that it is a background process.
  • A condition that is not an orphan process group: there is a process in this process group whose parent belongs to another group of the same session.
  • Signal SIGKILL SIGSTOP cannot be ignored or captured.
  • The storage image when the core file copy process terminates.
  • The kill command and the kill function simply send a signal to a process or group, and whether the process terminates depends on the type of signal and whether the process is scheduled to catch the signal. $kill -USR1 7216
  • Void (*signal(int sigNO, void (*func)(int)))(int) Returns the previous processing configuration on success, and SIG_ERR is returned on failure. The current processing of a signal cannot be determined without changing its processing. Func specifies SIG_IGN or SIG_DEL for ignore or default processing.
  • Exec invalidates the capture, and the address of the capture function may be meaningless.
  • The process catches a signal and executes the signal-handler function func, which then executes the code that was executing when the signal occurred. Reset signal action to default after processing the first signal?
  • Read Write If part of the data is interrupted, you can choose whether it succeeds or fails.
  • Call a non-reentrant function in a signal handler and the result is unforeseeable.
  • Raise (int SIGno) == kill(getPid (), int signo) The process needs permission to send signals to other processes. Sends a null signal to a nonexistent process, killing returns -1.
  • The process ID will be reused.
  • The semantics of the signal function are implementation-dependent, and it is best to use the SIGAction function. Sigaction (SIGNO [signal number of specific action to be detected or modified], & ACT [if not empty to modify its action], & OACT [if not empty to return the last action of the signal])
  • Sigemptyset (&act.sa_mask)
  • When processing a given signal, if it occurs again, they are usually not queued and will be blocked until the processing of the previous signal has finished. The kernel only passes this signal once the blocking is over. [Shielding word 0 means no signal blocking, which signal processing function is implemented to shield which signal]
  • If a signal is received during the blocking of a Unix low-speed system call, the low-speed system call is interrupted.
  • Void abort(void) causes the abnormal program to terminate. When the child terminates, it sends a SIGCHLD signal to the parent. Sig2str STR2SIG is the signal number and signal name conversion function.
  • Multithreaded programs running on a single processor can still improve response time and throughput.
  • A thread ID is valid only in the process environment to which it belongs, and therefore may not be unique.
  • Pthread_t pthread_self(void) Gets the ID of its own thread. The main thread can use the thread ID to control which thread handles which jobs. There is a race between the new thread and the main thread, and the thread ID returned by the main thread is not safe. If the thread ID is long it’s probably an address.
  • If any thread calls exit,_Exit, _Exit the entire process terminates. Thread termination: 1. The start function returns. 2 is cancelled by another thread of the same process. 3 pthread_exit
  • Void pthread_exit(void* rval_ptr) int pthread_join(pthread_t thread, void** rval_ptr)
  • Things declared in the thread do not go out of the belt. The thread terminates from the thread function and the cleaner is not called. Waitpid = = pthread_join. Pthread_detach allows the thread to detach (not interested in thread termination status). When the detached thread terminates, resources are reclaimed and the detached thread cannot pthread_join.
  • One scenario for locking: the mutex is locked until the reference count is incrementing, subtracting, and checking for zero. [link with similar number of references]
  • Read/write locking in read mode is shared mode [concurrent read], and in write mode is exclusive mode [write alone].
  • The virtual address space of a thread is shared by multiple threads. A recursive mutex can be locked recursively.
  • Both threads and signals involve the issue of reentrant functions. Signal: Capture functions will fail if they write to global data. Thread: Multiple threads call the same function at the same time. Each thread has its own signal-masking word. Signal handlers are shared in process.
  • Errno is redefined as thread-private data. Key is used to protect thread-private data.
  • When a process with multiple threads forks, only the forked thread is copied into the child process, and the lock is uncontrollable and can be avoided by exec immediately.
  • pread(…) Make offset setting and data reading an atomic operation.
  • Ps -a [Display process status owned by other users] x [Process status not controlled on the terminal] j [SESSION ID, process group ID..]
  • If you fork the daemon twice, it is not the first session and does not acquire the control terminal. Fork Ensures that the child process is not the process group leader.
  • Lockfile (fd) Lock a file lockf(lockfd, F_TLOCK, 0L) ensures that only one daemon is running.
  • A low-speed system call is a type of system call that can block a process forever.
  • Non-blocking IO: the operation cannot complete, and an immediate error is returned [stop there for further processing, similar to trylock trying to lock]. There are two ways to specify the descriptor as non-blocking IO: O_NONBLOCK when open; FCNTL (fd, CMD, &lock) turns on the O_NONBLOCK flag.
  • Record lock == byte range lock: When one process reads or modifies a part of a file, it prevents other processes from modifying the same part of the file. On some systems the final state of a file depends on the last process that wrote the file.
  • The same process can repeatedly lock the same byte range, new lock for old lock. You can test whether another process locks a record.
  • Locks are associated with both processes and files. Fork does not inherit the parent’s lock on the file. Exec The new program inherits the lock of the original program.
  • Some UNIxes provide system call tracing features.
  • STREAM: A generic method for constructing kernel device drivers and network protocol packages.
  • IO multiplexing: Execute block read. Blocking is blocking the entire process. If multiple paths do not want to affect each other, they have to fork multiple processes, each processing its own file descriptor. CPU consumption with non-blocking read polling descriptors.
  • The idea of IO multiplexer: Construct a list of descriptors and call a function until one of the descriptors in the table is ready for IO. The function returns telling the process which descriptors can I/O. It is used for terminal I/O and network I/O. Select (0, NULL, NULL, NULL, & TV) is equivalent to sleep, accurate to microseconds.
  • Asynchronous IO: The basic idea that tells the kernel to use a signal to tell a descriptor when it is ready to do IO. System V asynchronous IO calls to the IOCTL set up signal processing, only for STREAMS devices and STREAMS pipes. BSD asynchronous IO set signal SIGIO handler, call FCNTL set O_ASYNC file as asynchronous IO. This applies only to terminals and network descriptors.
  • Storage mapping IO: Unsigned char* mmapBuf = (unsigned char*)mmap(NULL fileSize, PROT_READ), MAP_SHARED,fd [mapped file], 0 [mapped byte start offset in file]) munmap((char*)mmapBuf, fileSize) [unmapped] msync Flush to disk
  • IPC: various channels, message queues, semaphores, shared storage, sockets, STREAMS
  • Pipeline: half duplex [data can only flow in one direction]; Can only be used between processes of a common ancestor, usually between parents after forking. Int pipe(int Filedes [2]) fork f[0]<- -f[1] has two copies, one of each closed
  • Sh -c cmdString specifies that the shell will extend the special character [*.c] in the string.
  • ${PAGE:-more} If PAGE is defined, use more.
  • Full buffering is the default for pipe standard IO.
  • Data can also be exchanged between unrelated processes through FIFO. Int mkFIFo (pathname, mode_t mode) is similar to creating a normal file.
  • Msgget semget shmget specifies a key key_t. Ftok can generate a key from a pathname and project ID key_t ftok(path, ID)
  • MSGCTL semctl SHMCTL Modify the UID, GID, and mode IPC have built-in restrictions that can be modified by configuring the kernel. Ipcs View IPCRM delete
  • MSGRCV can be non-fifO
  • The semaphore value indicates whether the corresponding resource is available. Semop (_ID, buf[] all or none of the operations in array are executed), 1) wait for semaphore, release resource, acquire resource Semctl gets semaphore information and sets semaphore information.
  • Using a semaphore (actually a synchronization primitive rather than IPC), we create a semaphore set containing a single member with the initial value of 1. Call semop when allocating resources with sem_op -1 and call semop when freeing resources with sem_OP 1. SEM_UNDO is set each time to handle the case when the process terminates and resources are not released.
  • Shmget can either be created or referenced (like msgget). SHMCTL IPC_RMID Reduces the number of references without actually deleting them. Shmid is different from pickey. Shmget returns shmid. SHMDT disconnection is not deleted, and the number of references is reduced by one.
  • Sockets are used by processes on different computers to communicate with each other, and other processes run transparently. Many network protocols can be used, TCP/IP being common.
  • Create a socket int socket(int domain [e.g. Ipv4internet domain], int type, int protocol) returns the socket file descriptor.
  • Int shutdown(int sockfd, int how) Disables input/output on the socket. Uint32_t htonl(Uint32_t hostint32) etc for the conversion of processor byte order and network byte order.
  • Inet_pton (AF_INET, host.c_str(), &m_addr.sin_addr) converts the text string to the binary address of the network byte order
  • The poll Select function checks the state of the file descriptor and can be used to determine whether to perform an operation on the file descriptor.
  • setsockopt(_sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeo, len)
  • Int fattach(int fileds, const char* path) associates the STREAMS pipe with a name in the file system.
  • Unix domain sockets are used for interprocess communication on the same machine. int ssocketpair(int domain, int type, int protocol, int sockfd[2])
  • Terminal IO: function tcgetattr TCsetattr Terminal IO control functions mostly start with TC
  • Many database implementations use two files: an index file and a data file.