1-Shell Scripting
1-Shell Scripting
2. Init process.
3. Run levels.
8. Forking.
9. Execve.
Process Control:
File Management :
Memory Management :
The init process in Linux is the first process the kernel starts after booting.
It plays a critical role in setting up the environment for the system to run
and ensuring all necessary services are started.
Kernel Boot
init Configuration
Run Levels
Service Scripts
User Login
Kernel Boot:
When the system boots, the Linux kernel is loaded, and
control is passed to init.
init Configuration:
init reads its configuration from /etc/inittab. This file
contains instructions on what the system should do
based on the current run level. init then moves to the
default run level.
Run Levels :
Run level Description
A run level is a state of init and the whole system
System halt ,the system can be safely powered off with no
defines what system services are operating. Run 0
activity.
levels are identified by numbers. Run level is a
mode or state in which a Linux system operates. It 1 Single user mode.
has a crucial role in the management of the Linux
2 Multiple user mode with no NFS (network file system).
System.
Multiple user modes under the command line interface and
3
not under the graphical user interface.
4 User-definable.
Multiple user mode under GUI and this is the standard run
5
level for most of the LINUX-based systems.
Service Scripts:
For each run level, the system has
associated scripts located in directories
like /etc/init.d/. These scripts are executed
in sequence when entering a particular run
level. The scripts are used to start, stop, or
restart system services such as
networking, logging, and daemons.
User Login:
Once the services have been initialized, init
starts the login process
Kernel Boot:
kernel loads systemd as the first user-space
process. it uses targets to define system states.
systemd Targets:
Targets in systemd are like run levels in that they
define a set of services that should be started.
However, systemd allows for more fine-grained
control over the dependencies between services.
Common systemd.
Unit Files:
system-d uses unit files to manage services. These files define how a
service should start, stop, and be managed. Unit files are stored in
directories like /etc/systemd/system/.Each service has a corresponding
unit file .
Parallelization:
One of the key features of systemd is that it starts services in parallel (as
opposed to the sequential execution in SysVinit). It analyzes service
dependencies and starts services in the most efficient order, speeding
up the boot process.
Service Management:
system-d allows administrators to start, stop, restart, or enable/disable
services using the systemctl command.
User Login:
After all necessary services have started, systemd proceeds to launch the
login service (such as Getty for terminal login or a graphical login
manager).
A shell is a special user program that provides an interface for the user to
use operating system services. Shell accepts commands from users and
converts them into something which the kernel can understand. The shell
gets started when the user logs in or starts the terminal.
Bash was created by Brian Fox in 1987 as part of the GNU Project to replace the Bourne Shell.
Features:
• Command-line editing
• Job control
• Command history
• Tab completion
• Scripting enhancements (functions, arrays, etc.)
- A shell provides a command-line interface, allowing users to interact with the operating
system and execute commands.
- The shell serves as an interpreter for running programs and scripts. It can execute both
system-level commands and user-created scripts.
The Executable and Linkable Format (ELF) is the standard file format for
executable, object code, shared libraries, and core dumps on Linux and
Unix-like systems.
• Elf Header
• Section header and different sections
• Program header and different program sections
• Object code
• Debugging information
• Type – Halfword in bytes 16-17 that specifies the object file type
– ET_EXEC (2) for executables, ET_DYN (3) for shared objects,
ET_REL (1) for relocatable files, etc.
• Entry Point – Word at bytes 24-27 stores the memory address for
the entry point – initial instruction executed when loading
executable.
SEITech Solutions - Confidential Information 22
W H AT I S D Y N A M I C L O A D E R ?
Dynamic Linking
Static Linking
The process of combining all necessary library routines The process of linking external libraries and references at
Definition and external references into a single executable file at runtime, when the program is loaded or executed.
compile-time.
Occurs at runtime.
Linking Time Occurs at compile-time.
Less flexible, as any updates or changes to the libraries More flexible, as libraries can be updated or replaced without
Flexibility require recompilation and relinking of the entire recompiling the program.
program.
2. Memory Mapping: The dynamic linker maps the sections of shared libraries (text, data, etc.) into specific memory
regions within the process's address space. This mapping involves creating memory-mapped regions.
3. Memory Loading: The actual content of the shared libraries on disk is loaded into the memory-mapped regions. This
means that the code and data of the libraries are now resident in the system's physical memory.
4. Symbol Resolution: The dynamic linker resolves symbols (functions, variables) used by the process and updates
references in the process's code to point to the memory-mapped addresses of the shared library.
5. Runtime Execution: During the execution of the process, when functions or data from shared libraries are needed, the
process accesses the memory-mapped regions in memory, not from disk.
6. Memory Protection: The memory-mapped regions are protected by the operating system's memory protection
mechanisms, ensuring that unauthorized access or modification of the shared library's memory is prevented.
7. Sharing Among Processes: Memory-mapped regions for shared libraries can be shared among multiple processes that
use the same libraries. This reduces memory consumption since the same library can be loaded into memory once and
shared among multiple processes.
File type: Specifies whether the file is a regular file, directory, symbolic link, or other types.
File permissions: The read, write, and execute permissions for the file.
Owner: The user ID (UID) of the file's owner.
Group: The group ID (GID) of the file’s group.
Size: The total size of the file (in bytes).
Creation time (ctime): Time when the inode was created or last changed.
Modification time (mtime): Time when the file's content was last modified.
Access time (atime): Time when the file was last accessed (read or executed).
Number of links: The number of hard links pointing to this inode.
Pointers to data blocks: Addresses to the actual data blocks on the disk where the content of the file
is stored.
Inode Number: Each inode is identified by a unique inode number within a filesystem. This inode
number is used internally by the filesystem to access the inode