0% found this document useful (0 votes)
0 views

01_Linux_System_Basics

Linux is an operating system derived from UNIX, which was developed in the 1960s and is known for its multitasking and multi-user capabilities. The Linux kernel manages system resources and facilitates process execution, while the C Standard Library provides a set of functions for developers to interact with the kernel through system calls. Various commands, such as ps and pgrep, can be used to manage and view processes within the Linux environment.

Uploaded by

samsauder0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

01_Linux_System_Basics

Linux is an operating system derived from UNIX, which was developed in the 1960s and is known for its multitasking and multi-user capabilities. The Linux kernel manages system resources and facilitates process execution, while the C Standard Library provides a set of functions for developers to interact with the kernel through system calls. Various commands, such as ps and pgrep, can be used to manage and view processes within the Linux environment.

Uploaded by

samsauder0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Linux System Basics

1. Linux is based on an earlier operating system named UNIX. UNIX is a multitasking,


multi-user operating system that can be used on a variety of computer platforms.
UNIX was developed in the 1960s at AT&T's Bell Laboratories. The first version, called
UNICS, was written by Ken Thompson and Dennis Ritchie in 1969, and was written in
assembly language. UNIX Version 4 was written in the C programming language in
1973.

NOTE: The name UNIX was a pun on Multics, an earlier time-sharing operating system
project at Bell Labs.

2. Linux constitutes the following components and features:


 A Kernel that manages:
o Program execution time
o Program memory allocation
o Interrupt processing
o System call processing
o File storage and management
o I/O (Input/Output) communication
 File I/O communication
 Network I/O communication
 A standard runtime library that consists of function calls (library routines) used by
software developers to write computer programs. Some of the functions in the
standard runtime library make kernel system calls. For Linux programming, the
standard runtime library is the C Standard Library.
 A command-line interface (CLI), often referred to as a shell, that operates as an
interface between the kernel and the user.
 A set of standard applications. NOTE: The set of standard applications depends on
what distribution of Linux is installed.

3. The primary purpose of the kernel is to manage a computer’s resources so that


efficient multiprogram execution can be obtained. The managed resources of a
computer system include the CPU, main memory, file system, and the I/O devices and
the associated I/O device drivers.
4. Each process is allocated CPU time (termed the process time-slice) by the operating
system’s scheduler, and each process is allocated portions of main memory by the
operating system’s virtual memory manager.

5. A process can be in one of several states. A process transitions from one state to
another via state transitions caused by interrupts, operating system schedular
dispatches, and I/O events.

6. Processes execute in user mode and the kernel operates in kernel mode. Processes
use the services the operating system provides via the operating system’s system call
interface. The system call interface is the fundamental interface between an
application and the kernel. The system call interface is documented in Section 2
System Calls of the Unix Programmer’s Manual.

7. The system call interface is defined using the C programming language. Typically, for
each system call there’s an associated C function defined in the C Standard Library. A C
program makes function calls using the C Standard Library, and the C Standard Library
makes system calls using the system call interface. The C Standard Library is
documented in Section 3 Library Functions of the Unix Programmer’s Manual.
NOTE: Some system calls have an associated C Standard Library wrapper function. The
C Standard Library wrapper function makes a corresponding system call.

NOTE: The functions defined in the C Standard Library may or may not make system
calls, and some system calls can be made directly by a C program without calling
functions defined in the C Standard Library.

NOTE: It’s common to refer to CPU exceptions as CPU faults. The term exceptions is
often used as a generic term to include all traps, interrupts, and faults as a type of
exception.

C Library Functions and System Calls

Traps to Trap Table


Kernel Trap, Interrupt, and Exception Handlers

User Mode Process Issues Signal – Signal Generates Trap – Kernel Mode Trap
Handler Processes Trap
8. The following program outputs the process’ process ID (PID) and the process’ parent
PID (PPID) using the C library function syscall. The C library function syscall is a
wrapper function that invokes a syscall system call. This is commonly termed an
indirect system call. The system call invoked is given by the syscall function’s first
parameter value. The syscall function is useful when invoking a system call that has no
associated wrapper function in the C Standard Library.

Invoking the syscall function causes a trap to the operating system’s system call trap
handler. The system call trap handler maps the trap number to an entry in the
operating system’s system call trap table. The system call trap table is indexed via the
system call trap number. The entries in the system call trap table corresponded to
system call addresses.

NOTE: Symbolic constants for system call numbers can be found in the header file
<sys/syscall.h>.

The pid_t data type represents process IDs. You can get the process ID and parent
process ID of a process by calling syscall. The pid_t data type is a signed integer type
which is capable of representing a process ID. In the GNU library, this is an int. The
syscall C Standard Library wrapper function executes assembly instructions that cause
a trap to the operating system’s trap handler.

Linux Manual Pages


https://man7.org/linux/man-pages/man2/syscall.2.html
https://www.man7.org/linux/man-pages/man3/stdin.3p.html

Program
linux\01_System_Calls\01_syscall_Standard_C_Lib_SYS_getpid
NOTE: The operating system loader loads programs into memory and creates an
associated process table entry in the operating system’s process table for the loaded
program (a program loaded into memory is often termed a process). The process is
assigned a process id (PID). The operating system uses a process’ PID to find the
associated process table entry in the process table.

To view process IDs (PIDs) from a shell, use the ps command, the pgrep command, or
the top command. The ps command with options like ps -aux or ps -e displays all
running processes, including their PIDs. The pgrep command allows you to search for
processes by name and retrieve their PIDs. The top command provides a real-time
interactive view of processes, including their PIDs.

ps aux: Displays a comprehensive list of all processes, including PIDs, user, CPU usage,
and memory usage.

ps -e: Displays all processes running on the system.

ps -ef: Displays a full listing of all processes, including the user, parent PID, and start
time.

pgrep <process_name>: Finds the PIDs of processes whose names contain the
specified text.

pgrep -l <process_name>: Lists PIDs and process names.

pgrep -u <username> <process_name>: Finds processes owned by a specific user.

pgrep -x <process_name>: Finds processes whose exact command name matches the
specified text.

top: Provides a real-time, interactive view of processes, including their PIDs, CPU
usage, memory usage, and more.

Use the K key followed by the PID and a signal number (e.g., 15) to kill a process.

For example, to find the PID of a process named "firefox", you can use pgrep firefox or
ps aux | grep firefox.

9. The following program outputs a message to standard output using the syscall
function. In this case, the syscall function is passed a system call number, a file
descriptor value, a pointer to the first byte of an array, and the length of the array.

Linux Manual Pages


https://man7.org/linux/man-pages/man2/syscall.2.html
https://www.man7.org/linux/man-pages/man3/stdin.3p.html

Program
linux\01_System_Calls\02_syscall_Standard_C_Lib_SYS_write
References
https://en.wikipedia.org/wiki/Unix

https://www.tutorialspoint.com/assembly_programming/assembly_system_calls.htm

You might also like