Linux is the most commonly used open source operating system today. As an operating system, it sits underneath all of the other software, receiving requests from other software programs and relaying these requests to the computer's hardware.
In this article we will go through linux operating systems concepts and applications. You will get guidance with relevant theory and practical source code programs, illustrations to understand how linux is practically used in the system to implement project requirements.
Learn to develop embedded systems, interfacing electronic peripherals through real time projects and get required practical skills for software jobs
An operating system works closely with the hardware system. The operating system acts as the interface between user and hardware. So in order to fully understand the Linux operating system, you need to understand the basics of the underlying hardware. At minimum a computer system consists of a CPU or microprocessor, the memory and a number of slots for the peripheral controllers.
CPU calculates, performs logical operations and manages data flows by reading instructions from memory and then executing them. CPU operates on binary data where each digit represents a power of 2. Generally numbers are represented by hexadecimal where each digit represents a power of 16. So 8 is written in binary as 0b1000 and in hex as 0x08. Similary 14 is written in binary as 0b1110 and in hex as 0x0E.
The CPU execution is driven by the system clock(e.g. 100MHz) which generates regular clock pulses to the processor and at each clock pulse, the cpu does some work. For example an instruction can be to read the contents of memory at location A into register B. So CPU executes one or more instruction every clock pulse. Registers are the CPU's internal storage, used for storing data and performing operations on it and can be 32 bit/64 bit wide.
Most CPUs have special purpose registers such as Program Counter which points to the next instruction to be executed, Stack pointer which helps in accessing, saving and restoring large amount of external read/write RAM for facilitating temporary storage of data, processor status to hold information like the current state of the processor(e.g. kernel mode and user mode).
Instructions have to be fetched from memory as they are executed. Read only memory(ROM) are used to store permanent data and RAM is used for temporary storage of data. System bus is divided into three logical functions, the address bus which specifies the memory locations (addresses) for the data transfers, the data bus((bidirectional and allows data to be read into the CPU and written from the CPU) which holds the data transfered and the control bus contains various lines used to route timing and control signals throughout the system. Peripherals are real devices, such as graphics cards or disks controlled by controller chips on the system board or on cards plugged into it.
Linux is a unix-like operating system. In linux all commands are run using a terminal provided by the linux system. The linux terminal can be used to do all administrative tasks. The linux commands are broadly divided into File System Commands, Process Management Commands, File Permission Commands, Searching commands, System Info Commands, File Compression Commands, Networking Commands, Process Management commands. All these category of commands are illustrated here by examples.
A process is an active program i.e. a program that is under execution. It is more than the program code as it includes the program counter, process stack, registers, program code etc. Compared to this, the program code is only the text section. All the practical aspects of how to create different types of processes, running the process and observing the process in the linux process list are illustrated here
A thread is a lightweight process that can be managed independently by a scheduler. It improves the application performance using parallelism. A thread has to be created by a parent process. All the practical aspects of how to create threads, managing threads are illustrated here here
Following are the difference between a linux process and thread.
In linux Inter Process Communication(IPC) is a mechanism that allows processes to communicate with each other and synchronize their activities with other processes. Linux supports a number of Inter-Process Communication (IPC) mechanisms such as signals, pipes, message queues, semaphores, shared memory.
Signals are used to signal asynchronous events to one or more processes. A linux signal could be generated by a keyboard interrupt or an error condition such as the process attempting to access a non-existent location in its virtual memory.
A pipe is a form of re-direction and is used to send the output of one command program or process to another command program or process.
Message queues allow one or more processes to write messages, which will be read by one or more reading processes.
Semaphore is a location in memory whose value can be tested and set by more than one process. The test and set operation is, so far as each process is concerned, uninterruptible or atomic; once started nothing can stop it. The result of the test and set operation is the addition of the current value of the semaphore and the set value, which can be positive or negative. Depending on the result of the test and set operation one process may have to sleep until the semphore's value is changed by another process. Semaphores can be used to implement critical regions, areas of critical code that only one process at a time should be executing.
Shared memory allows one or more processes to communicate via memory that appears in all of their virtual address spaces. The pages of the virtual memory is referenced by page table entries in each of the sharing processes' page tables. It does not have to be at the same address in all of the processes' virtual memory. As with all System V IPC objects, access to shared memory areas is controlled via keys and access rights checking. Once the memory is being shared, there are no checks on how the processes are using it. A real application project using shared memory is implemented here
A socket is one endpoint of a two-way communication link between two programs running on the network. Client and server communicate using IP sockets over a common port. Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request. The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. Client makes a connection request to server using TCP/IP, server port and server accepts the connection request. Upon acceptance, the server gets a new socket bound to the same local port and starts communicating with the client. A real application project using Internet protocol sockets is implemented here
The system bus connects the CPU with the main memory and is separate from the buses connecting the CPU with the system's hardware peripherals. Collectively the memory space that the hardware peripherals exist in is known as I/O space. The CPU can access both the system space memory and the I/O space memory, whereas the controllers themselves can only access system memory indirectly and then only with the help of the CPU. For example floppy disk controllers will see the address space of its own registers, not the system memory. CPU will have separate instructions for accessing the memory and I/O space.
A Linux system is basically divided in three major components: Linux File System (LFS), Shell and Kernel. Kernel is the core program which manages system hardware devices. Shell provides user interface to run the commands. File system organizes the data in systematic way. User space programs don't have direct access to the system main memory. They get access to the main memory indirectly using system calls.
There are times when controllers need to read or write large amounts of data directly to or from system memory. For example when user data is being written to the hard disk. In this case, Direct Memory Access (DMA) controllers are used to allow hardware peripherals to directly access system memory but this access is under strict control and supervision of the CPU.
|pthreads practical applications illustration in linux|
|Process practical applications illustration in linux|
|Process in Linux|
|Writing practical makefiles linux examples illustrations|
|Linux os concepts internals applications in a nutshell|
|Linux important commands illustrations examples|
|Shared library development with gcc in linux|
|Arrays in C|
|Bit fields in C|
|Structure in C|
|Functions in C examples|
|Memory layout of C program in linux|
|How to write makefile in linux for c|
|Embedded c programming novice to professional in 24 hours|
|C control flow loops macros operators examples|
|State machine implementation in C example|
|C programming debugging exercises assignments solutions|
|Pointers in C examples|
|Strings in C examples|
|Data types in C with examples|
|C standard library function fgets with example|
|strcpy strncpy in c example illustration|
|C programming compiler errors warnings debugging|
|strcat, strncat, strcmp, strncmp, strchr, strrchr library functions|
|Storage classes in C|
|Microcontroller fundamentals in a nutshell|
|SPI protocol theory of operation|
|How UART protocol works?|
|I2C programming in embedded C|
|Linux software development|
|C programming & applications|
|Embedded systems development|
|Variables, Variables scope, Datatypes|
|Strings and its practical applications|
|Functions and its practical applications|
|Pointers and its practical applications|
|Arrays, Two dimensional arrays|
|Enums, Bit fiddling, practical applications|
|Structure, Unions, practical applications|
|Control flow, loops, operators, Macros|
|Data structures, practical applications|
|Python Data Type: Tuples, Files & Applications|
|Python Data Type: Strings & Applications|
|Python Data Type: Dictionary & Applications|
|Python Data Type: Objects, Classes & Applications|
|Python Data Type: Lists & Applications|
|Python Data Type: Numbers & Applications|
|Git Version Control|
|Linux IPC Mechanisms|
|Linux OS Internals|
|Linux OS Commands|
|Linux Processes and Threads|
|Time and Distance|
|LCM and HCF of numbers|
|SPI Protocol & Applications|
|I2C Protocol & Applications|
|UART Protocol & Applications|
|Microcontrollers, Tools & Peripherals|