Read Normal Linux Programming (Part 1 Only)

I will rewrite it later because it is summarized roughly.

Part 0

--The world of Linux is made up of three concepts. --File system --Process --Stream

Part 1

Linux basic terminology

Chapter 1

――It is written in man which header file should be included to use a certain function. --The file name expansion function (glob) such as "*" and "?" Is a shell function.

Chapter 2

--Linx software package --Shell (bash, ash, csh, tcsh, zsh, pdksh, ...) - util-linux(init, getty, login, reset, fdisk, ...) - procps(ps, pstree, top, ...) - GNU coreutils(ls, cat, mkdir, rmkidr, cut, chmod, ...) - GNU grep, findutils, diffutils(grep, find, diff, ...) - GNU libc --Various basic libraries (ncurses, zlib, GDBM, ...) --Development environment (gcc, binutils, make, biscon, flex, header files, ...) - X Window System --GNOME and KDE

--Linux distribution - Red Hat, CentOS, Ubuntu, Debian, SUSE, Gento

--Linux is a kind of Unix-like OS.

--Most macOS is derived from FreeBSD.

--Kernel --It is the core of the OS. ――It consists of one program. --Manages all the hardware and software that make up the computer.

--Files named vmlinuz, vmlinux, vmlinuz-XXX in the root directory are the main body of the Linux kernel program. --Strictly speaking, the word "Linux" refers to the kernel. --Device --The kernel controls the following physical hardware. - CPU

--Device driver --A software component for operating a specific device.

--System call --A mechanism that asks the kernel for work. --System-> Kernel --Premise --Since the direct interaction with the hardware is limited to the kernel (that is, only the device driver), when an ordinary program wants to operate the hardware, it has to ask the kernel to do the work indirectly. ――The kernel is the greatest program in the system, but it is also the program that is used at the bottom. --The system call call is also a normal function call. --Example - open, read, write, fork, exec, stat, unlink

--Kernel summary --The Linux world is the world created by the Linux kernel, and the only way to get that kernel to do its job is to use system calls. --For file system process streams, create an image through system calls.

--Library function --Functions that can be used in addition to system calls when programming. --Example: printf (), exit (), strlen (), strcpy (), ... --If you * link * a library function, you will be able to call that function.

Chapter 3

3-1. File system

--ls -l command --The incidental information of the file can be displayed.

Summary

--Hold some data --Attachment information is attached --Can be specified by name (path)

--The file system is on a physical storage medium such as SSD, HDD, or USB stick. --Partition --Disk partition delimiter. --Mount --Prepare a file system on the partition and create a huge directory tree.

3-2. Process

--Process --A running program. ――You can create any number of processes with one program. --Program --A word that includes data that exists in the form of a file.

--Process ID --The number in the second column from the left in the output of the ps command. --Specify the process uniquely. --Signal --Supports a mechanism to stop the process by pressing Ctrl + C. --The kernel sends an interrupt signal to the process, and the process that receives it terminates spontaneously. --It is a mechanism that has been around for a long time in UNIX and occupies a very important position in UNIX (Linux) programming.

3-3. Stream

--Stream --Refers to the flow of bytes. The path through which the byte sequence flows. --In other books, it is called "file" or "open file". --FILE value --FILE type --Data structure used when manipulating streams. --STREAMS kernel module - STREAMS --Kernel module used to serve the stream --Example 1 where a stream is used --When a process wants to access the contents of a file.

  1. Ask the kernel (using a system call) to create a stream that connects to the file.
  2. Then again, using system calls, manipulate the stream to retrieve the contents of the file.

--Example 2 where a stream is used --Pressing a key on the keyboard. --It is considered to be a stream that sends a string of bytes representing the pressed key.

--The device file exists as a starting point for getting the stream.

--Pipe --Streams with processes at both ends --Pipe when using less command or grep command --How the pipe works

  1. First, execute each command as an independent process at the same time.
  2. Connect the processes with a stream (pipe).

--Network communication --The stream extends to another computer. --Connecting a process on one computer to a process on the other computer. --There is no problem as long as the byte sequence is transported properly.

--Interprocess communication --Like pipes and network communications, processes exchange data and communicate with each other through streams. --There is also an interprocess communication mechanism that uses something other than a stream. - POSIX IPC

Summary

--File system --A place to name and save the data --Process --Subjects doing some kind of activity --Stream --The means by which a process exchanges data with the file system and other processes

――With this alone, you can roughly talk about the structure of the Linux OS.

Chapter 4

4-1. Users and groups

--Multi-user system --A system that can be used by multiple users at the same time, such as Linux. --- UNIX was. --By keeping files that are important to the system owned by a user other than the user who normally uses them so that only the owner can change them, you will not accidentally delete important files.

--Superuser - root --You have the authority to modify, delete, and stop any file.

--Group --A group of users. --Giving authority to a group means giving authority to all members of that group. --Permission to use specific device files. --Each user always belongs to at least one group. --If you create a user with the useradd command, you can specify a group with the -g option.

--Permissions --There are 3 user categories and 3 permissions. --The file has a fixed user and group that owns it. --The user who owns the file --Users who belong to the group that owns the file --Other users --Type of authority --Read (read, r) --Write (w) --Execute (x) --Example: - rw-r--r-- --Owner read / write, own group readable, other users readable. --Ordinary file. - rwxr-xr-x --Owner read / write can be executed, owning group can be read, and other users can be read. --Programs and directories. - rw------- --Only the owner can read and write. --Files that are bad for anyone other than you, such as the SSH private key.

--Octal notation of permissions --Example: - rwxr-xr-x - rwx=4+2+1, r-x=4+0+1, r-x=4+0+1 = 755 - rw-r--r-- - 644

--Directory permissions --If readable --You can get a list of files in it --ls command etc. --If writable --You can create or delete new files in it --If executable --You can access (read / write) files in that directory.

--Credentials --A user as a process attribute --"Operate as user A" = "Operate processes with the attributes of user A" --A certificate that says "This process is acting on behalf of this user on Linux." --The kernel looks at the certificate to determine permissions. --In the process of logging in, a process with a certificate is created on the system.

--Username and user ID --The kernel handles only the user ID corresponding to the user name.

--User database --A file that describes the correspondence between user names and user IDs. --Generally located in / etc / password. --Example: - root:\x:0:0:root:/root/:/bin/bash --User root, password x, user ID 0, user group 1

4-2. Shell and terminal

--The command line consists of the following two.

  1. shell
  2. terminal

--Terminal --The part of computer hardware that people come into direct contact with.

--Terminal history --Teletype --A terminal that was used in large numbers in the early days of UNIX. --Printer output and typewriter input from a computer when there was no display. --Derived from the teletype, the terminal is sometimes called * tty * in UNIX. --Dumb terminal --A terminal that appeared after the teletype. --A display that can display only characters, a keyboard, and the hardware that accompanies it. --Character terminal --Early dumb terminals. --Only characters can be displayed on the display. --Bitmap display ――Express everything with a collection of fine colored dots. --X terminal --A model equipped with a bitmap display used to operate the X Window System. --Terminal emulator --All the terminals that were originally hardware have been turned into software. --MacOS Terminal.app, iTerm2, etc. --A state-of-the-art, throwback-like terminal that dares to input and output characters in a personal computer, which is a terminal with a modern bitmap display.

--Virtual console ――In Linux, the physical terminal is not used as it is, but a virtual console is sandwiched between them. --Software-like terminal.

--Character terminal and ASCII --When displaying "a" on a computer equipped with a modern GUI, create an image that expresses "a" in memory in advance, and instruct "Display such an image". - ASCII

--Terminal as a file, terminal as a stream --When represented as a file, you get a stream to connect to what is represented. --Reading the stream connected to the terminal gives input from the keyboard, and writing to the stream connected to the terminal can output characters to the display.

--Shell --A program that interprets and executes instructions from users. - sh, bash, csh, tcsh, zsh, ksh, ash --The shell is just a little special in that it is launched at login, and is itself just a program that reads and executes commands from a stream. --If the stream is connected to a terminal, it will output a command line prompt such as "$" or "%".

Recommended Posts

Read Normal Linux Programming (Part 1 Only)
Try normal Linux programming Part 7
Try normal Linux programming Part 2
Try normal Linux programming Part 3
Try normal Linux programming Part 4
Trying normal Linux programming Part 1
Linux command [read]
Read "Ordinary Linux Programming" at an in-house study session
[For memo] Linux Part 2
Linux standard textbook part 5
New Linux commands! !! Part 2
Linux standard textbook part 4
Read "Ordinary Linux Programming" at an in-house study session ~ 10.11 Exercises ~
Linux standard textbook memo 1 part 2
I read "Linux standard textbook"!
Read core voltage on Linux
Making sound by programming Part 2
Linux standard textbook memo part 6