Tuesday 24 October 2023

E02:Linux Network and Process Management

 What is a Process?

  • A process in Linux is a running program or task. It's an instance of a program that is being executed by the Linux kernel.
  • Each process has its own unique Process ID (PID), which is a numerical identifier that distinguishes it from other processes.

Process Characteristics:

  • Processes have their own set of resources, including memory, CPU time, file descriptors, and more.
  • Each process is isolated from other processes, meaning they can't directly access the memory or resources of another process.

Creation of Processes:

  • Processes are typically created in Linux through the fork() system call. This call creates a new process that is a copy of the calling (parent) process.
  • The exec() system call can be used to replace the program in the current process with a new one. This is commonly used for running different programs within the same process.

Process Hierarchy:

  • Processes in Linux are organized into a hierarchical structure, with a parent-child relationship. Each process, except the initial process (usually PID 1), has a parent process.
  • When a parent process spawns a new child process, the child inherits some attributes from the parent, such as environment variables and open file descriptors.
  • Monitoring ProcessesThe ps command is used to list currently running processes in the terminal, along with their details such as PID, status, and resource usage.
  • The top or htop commands provide a dynamic, real-time view of running processes and system resource usage.
  • You can send signals to processes using commands like kill to terminate or interact with them.

Daemon Processes:

  • Daemon processes are background processes that run without any user interaction, often providing system services. Examples include web servers, database servers, and printing services.

Process States:

  • Processes can be in different states, such as running, sleeping, stopped, or zombie. These states indicate what the process is currently doing.
Process Management

  •  ps Command: 
    • ps lists running processes.
    • ps aux shows detailed process information.
    • ps aux | grep username filters processes for a specific user.
  • cat /proc//status Command:
    • Displays detailed info about a process with a specific PID.
  • top Command:
    • Real-time process monitor. 
    • top -u username shows processes for a specific user. 
    • top -u root focuses on root user processes.
  • gnome-system-monitor: 
    • GUI-based system monitor for a graphical view of processes and system resources.
  • kill Command: 
    • kill  is used to stop a process by its PID. 
    • kill -9  sends a forceful SIGKILL signal to terminate a process.
  • systemctl Command:
    • sudo systemctl status service_name checks the status of a service.
    • sudo systemctl start service_name starts a service.
    • sudo systemctl stop service_name stops a service.

Network commands and configurations in Linux:

  • Network Interface Commands:
    • ifconfig, ip addr, and ip link display network interface information, including names and configurations.
  • Routing Information:
    • ip route shows routing information for the network your device is connected to.
  • Network Configuration File:
    • Network configuration files are found in /etc/netplan/.
    • The default configuration is in YAML format, and it often uses NetworkManager for network management.
    • These commands and locations are useful for managing and configuring network interfaces and connections in Linux.



E01: The Linux Filesystem

 Definition:

  • The file system is designed to manage non-volatile storage data by organizing it into files and directories, which can be accessed and modified by users and applications. 
  • Linux uses different file systems such as ext4, XFS, Btrfs, JFS, and ZFS to manage and store data on storage devices.
  • Linux file system has a tree like structure so AKA "directory tree"
  • It has a root directory that contains other files and directories

Understanding Pathnames in a Hierarchical File System
  • A pathname is a text string made up of one or more names separated by forward slashes (/), and it plays a crucial role in navigating a hierarchical file system. 
  • Pathnames guide users and applications on how to find and access files and directories within the file system tree. 
  • Here are some examples and key points to understand pathnames better:
    • Basic Structure: Pathnames are composed of one or more directory and file names, separated by forward slashes. For example, "/home" and "/etc/passwd" are pathnames.
    • Root Directory: A pathname starting with a forward slash ("/") indicates an absolute path, meaning it starts from the root directory. For instance, "/etc/passwd" starts from the root directory.
    • Relative Paths: Pathnames without a leading slash are considered relative paths. They are interpreted relative to the current working directory. For example, "usr/wc" might refer to a subdirectory "usr" within the current directory.
    • Whitespace Handling: Spaces in pathnames should be avoided, as they can lead to confusion and errors. In your example, "assignment 02 /check" includes spaces, which is not a recommended practice.
    • File and Directory Access: Pathnames guide users to access both files and directories. For example, "/etc" is a directory, and "/etc/passwd" is a file within that directory.
    • Hierarchical Structure: The structure of pathnames reflects the hierarchical nature of the file system, with directories containing files and subdirectories.
    • Common Pathnames: Common directories like "/home," "/etc," and "/var" have specific system-wide meanings and purposes. For instance, "/home" typically stores user home directories, and "/etc" contains system configuration files.
    • Absolute vs. Relative Paths: Absolute paths always start from the root directory and provide an unambiguous location. Relative paths depend on the current working directory and can vary depending on where they are used.
    • Pathname Errors: Care must be taken when specifying pathnames to avoid typos or incorrect paths, as this can lead to difficulties in locating and accessing files and directories.


Everything is a File in Linux: Seven Types of Files
  • In the Linux operating system, the philosophy is that "everything is a file." This means that almost all entities, including hardware devices and system processes, are treated as files. 
  • Even when new additions are made to the file tree, they are categorized into one of seven fundamental file types. 
  • These seven types of files in Linux:
    • Regular Files: 
      • Regular files are the most common type. They store data in a human-readable or binary format. This includes text files, documents, images, and executables. Regular files are represented by an "inode" in the file system.
    • Directories:
      • Directories are special files that contain lists of other files and directories. They provide the structure for organizing and navigating the file system. Directory entries map names to inodes.
    • Character Device Files:
      • Character device files represent devices that are read or written character by character, one byte at a time. These files are often associated with input and output devices, such as keyboards and terminals.
    • Block Device Files: 
      • Block device files are used to access block devices like hard drives and SSDs. They allow data to be read and written in blocks or chunks, typically larger than a single character.
    • Local Domain Sockets: 
      • Local domain sockets are a method of inter-process communication (IPC) on the same system. They allow processes to communicate with each other by sending and receiving data through socket files.
    • Named Pipes (FIFO): 
      • Named pipes, also known as FIFOs (First In, First Out), provide a way for processes to communicate through a temporary file. Data written to a named pipe is read in the order it was written, similar to a queue.
    • Link Files: 
      • Link files can be of two types: hard links and symbolic links (symlinks). Hard links point to the same inode as the original file, essentially creating multiple directory entries for the same data. Symbolic links (symlinks) are references to another file or directory by its path. They act as pointers or shortcuts to the target file or directory.


Tuesday 17 October 2023

D03: Basic Commands in Linux

  •  The commands are also known as "Programs" since written commands are being executed
Linux Command

1. ls
  • Lists the files and directories in the system
  • Syntax: 
    • ls [/directory/folder/path]
  • If you remove the path, the ls command will show the current working directory’s content. You can modify the command using these options:
    • -R – lists all the files in the subdirectories.
    • -a – shows all files, including hidden ones.
    • -lh – converts sizes to readable formats, such as MB, GB, and TB.
    • ls  - a - command to view hidden files
    • ls -al - gives detailed information of the files. The command provides information in a columnar format

2. Creating and viewing files
  • Concatenate or cat is one of the most used Linux commands. It lists, combines, and writes file content to the standard output. 
  • Syntax:
    • cat filename.txt
  • There are various ways to use the cat command:
    • cat > filen.txt – creates a new file.
    • cat file1.txt file2.txt > file3.txt – merges file1.txt with file2.txt and stores the output in filename3.txt.
    • tac file.txt – displays content in reverse order.
3. Deleting Files
  • Use the rm command to permanently delete files within a directory. 
  • Syntax:
    • rm [filename1] [filename2] [filename3]
  • Adjust the number of files in the command according to your needs. If you encounter an error, ensure you have the write permission in the directory.
  • To modify the command, add the following options:
    • -i – prompts a confirmation before deletion.
    • -f – allows file removal without a confirmation.
    • -r – deletes files and directories recursively.
  • Note* Use the rm command with caution since deletion is irreversible. Avoid using the -r and -f options since they may wipe all your files. Always add the -i option to avoid accidental deletion.
4. Moving files
  • Use the mv command to move or rename files and directories. To move items, enter the file name followed by the destination directory
    • mv filename.txt /home/username/Documents
  • Meanwhile, use the following syntax to rename a file in Linux with the mv command:
    • mv old_filename.txt new_filename.txt
  • mv command needs super user/ root user permission.  Currently, the command is executed as a standard user ,so above error is thrown
  • To overcome the error use command sudo
  • sudo:
    • program allows regular users to run programs with the security privileges of the super user or root user
    • Superuser do or sudo is one of the most basic commands in Linux. It runs your command with administrative or root permissions. Here’s the general syntax:
      • sudo (command)
    • When you run a sudo command, Terminal will request the root password. For example, this snippet runs useradd with the superuser privilege:
      • sudo useradd username
    • You can also add an option, such as:
      • -k – invalidates the timestamp file.
      • -g – executes commands as a specified group name or ID.
      • -h – runs commands on the host.
    • Notes*: Running a command with sudo privileges can modify all aspects of your system. Since misusing it may break your system, run the command with caution and only if you understand its possible repercussions.
5. Renaming Files
  • mv can also be used for renaming the file.  The syntax is
    • mv filename newfilename
6. Directory Manipulations
  • Use the mkdir command to create one or multiple directories and set their permissions. Ensure you are authorized to make a new folder in the parent directory. Here’s the basic syntax:
    • mkdir [option] [directory_name]
  • To create a folder within a directory, use the path as the command parameter. For example, mkdir music/songs will create a songs folder inside music. Here are several common mkdir command options:
    • -p – creates a directory between two existing folders. For example, mkdir -p Music/2023/Songs creates a new 2023 directory.
    • -m – sets the folder permissions. For instance, enter mkdir -m777 directory to create a directory with read, write, and execute permissions for all users.
    • -v – prints a message for each created directory.
  • rmdir- command is used to remove a directory
  • mv -  'mv' (move) command can also be used for renaming directories
  • Syntax of mv command-
    • mv directoryname newdirectoryname
7. Search Command
  • The global regular expression or grep command lets you find a word by searching the content of a file. This Linux command prints all lines containing the matching strings, which is useful for filtering large log files.
  • For example, to display lines containing blue in the notepad.txt file, enter:
    • grep blue notepad.txt
Other important Commands
  • History: 
    • Enter history to list previously executed commands. It lets you reuse the commands without rewriting them. To use it, enter this syntax with sudo privileges:
      • history [option]
  • Clear:
    • command clears all the clutter on the terminal and gives you a clean window to work on
  • pwd:
    • The pwd command prints your current working directory’s path, like /home/directory/path. Here’s the command syntax:
      • pwd [option]
    • It supports two options. The -L or –-logical option prints environment variable content, including symbolic links. Meanwhile, -P or –physical outputs the current directory’s actual path.
  • cd- :
    • Use the cd command to navigate the Linux files and directories. To use it, run this syntax with sudo privileges:
      • cd /directory/folder/path
    • Depending on your current location, it requires either the full path or the directory name. For example, omit /username from /username/directory/folder if you are already within it.
    • Omitting the arguments will take you to the home folder. Here are some navigation shortcuts:
      • cd ~[username] – goes to another user’s home directory.
      • cd .. – moves one directory up.
      • cd- – switches to the previous directory.
  • touch- :
    • The touch command lets you create an empty file in a specific directory path. Here’s the syntax:
      • touch [option] /home/directory/path/file.txt
    • If you omit the path, the command will create the item in the current folder. You can also use touch to generate and modify a timestamp in the Linux command line.
  • su- :
    • The su command lets you run a program in the Linux shell as a different user. It is useful to connect via SSH while the root user is disabled. Here’s the syntax:
      • su [options] [username [argument]]
    • Without any option or argument, this command runs through root and prompts you to use the sudo privileges temporarily. Some options are:
      • -p – keeps the same shell environment, consisting of HOME, SHELL, USER, and LOGNAME.
      • -s – lets you specify another shell environment to run.
      • -l – runs a login script to switch users. It requires you to enter the user’s password.

Thursday 12 October 2023

D02


 Introduction to LINUX:

Linux is an operating system, similar to Windows, iOS, and Mac OS. It plays a crucial role in managing hardware resources on computers. Notably, Android, a widely used platform, is built on the Linux OS. The operating system acts as an intermediary, enabling communication between software and hardware, making it essential for software functionality.

Most frequent tasks that you perform on PC is creating, moving or deleting Files

To manage your files , you  can either use

a. Terminal (Command Line Interface - CLI)

b. File manager (Graphical User Interface –GUI) 

WHY LEARN COMMAND LINE INTERFACE?

  • Despite the growing preference for GUI-based systems, the Command Line Interface (CLI) remains highly valuable and extensively utilized in scripting and server administration.
  • It offers greater flexibility and a wider range of options compared to GUI. Additionally, powerful features like piping and stdin/stdout are available in CLI but absent in GUI.
  • CLI simplifies certain tasks that might require navigating through multiple screens in GUI, condensing them into single commands.
  • CLI is resource-efficient, loading quickly and consuming minimal RAM, which becomes significant in resource-intensive situations.

Launching the  cli on ubuntu

Two ways to launch the terminal;

  • Go to the Das and type terminal Or 
  • we can just press CTRL + ALT + T

Once CLI is launched, we would find something as guru99@VirtualBox(seeimage) written on it.

Tilde '~' signs shows that the user in working in the home directory. If we change the directory the sign will vanish. Like in given second image.

While working as root user '#' is displayed.

  • root@VirtualBox:~#

 Present Working Directory 

  • The current working directory is the one that you are now viewing.
  • Upon booting up, the computer automatically logs on to the home directory.
  • We must use the command -pwd (print working directory) to find the directory that we are currently working on.

 Changing Directories 

  • 'cd' is the command to use to change the current directory.
  • The command cd~ is another option.

Moving to Root Directory

  • The '/' symbol in Linux indicates the file system root. Much like Windows' 'c:\'.
  • To access the root directory, type 'cd /'. In Windows, we use the backward slash '\', but in UNIX/Linux, we use the forward slash '/'.
  • The gap between cd and / must be remembered; else, an error message will appear.

Moving to Root Directory
  • Navigate through multiple directories at that same time by specifying its complete path.
  • Moving up one directory level:
  • for navigating up one directory level, try 'cd ..'
Here we use the 'cd ..' command, where the directory is moved up from 'Pelden' directory to /home.

Relative and Absolute Paths
  • There are two paths : 
  1. Absolute path and relative path
  2. Path in computing is the address of a file or folder 
For example -
  • Windows: C:\documentsandsetting\user\downloads
  • Linux: /home/user/downloads

Relative Path
  • Relative path comes in handy when browsing another sub-directory within a given directory.

Accessing Hardware Information 
  • Disk Space Usage :  displays the mounted file system disk usage. Also try out 
  • Memory:  display the RAM and Virtual Memory information. You can also use  
  • CPU Details:  or  display the information related to CPU.
  • Peripheral Component Interconnection(PCI) Devices: , displays the PCI devices list and its information.
  • All above information and more can be viewed with the single command  as well.

 

D01: Container Technology

 

Container Technology

What is a container?

A container refers to a typical software package that includes both the code and all the necessary components.

Container  ensures that the application operates consistently and efficiently across various computing environments.

 Containers offer a framework that enables the lightweight and unchanging packaging of application deployments.

 Within a container image, you'll find the code, runtime, system tools, system libraries, and configurations all bundled together.

 Linux Containers

A Linux container consists of isolated processes, powered by distinct images containing all required files for execution.

These containers are highly portable and maintain consistency as they transition through development, testing, and production stages.

Consequently, they offer faster and more efficient alternatives to traditional testing environments in development pipelines.

 WHY Linux?

To develop an application that can seamlessly work across different developer environments, pass quality assurance, and be deployed without extensive reworking, the solution is to use containers.

 Containers allow you to emulate various environments locally, matching specific configurations, libraries, and dependencies while avoiding the overhead of recreating server environments.

 This ensures consistency and portability throughout development and production, reducing the need for extensive troubleshooting and rewriting.

 Containers VS Virtualization 

Aspect

Virtual Machines

Containers

Technology

VMS are based on Virtualization technology

Containers are based  on containerization technology

Operating system

Include a complete operating system

Share the Host operating system

Resource Usage

Resource-intensive, consume more memory and storage

Lightweight, fewer resources being used

isolation

Strong Isolation between applications since each vms has its own OS

Efficient isolation but not as strong as VMS

Benefits of containers

Containers are a pathway to modernizing applications by decoupling them from their execution environments. This allows for faster and more efficient deployment across various environments. Containers package software and dependencies, ensuring consistency and reliability. The top benefits for businesses include increased agility and productivity, consistent application performance, improved scalability and infrastructure optimization, enhanced resilience, and high portability.

Docker is open-source software aimed at streamlining application development through isolated virtualized environments for building, deploying, and testing applications. While Docker is user-friendly, it introduces specific terms like Dockerfiles, images, containers, volumes, etc., which might be initially confusing for new users. Understanding these elements and their roles is crucial for a smoother learning process and efficient usage of Docker over time.

 Terminology

 

●A Dockerfile is a text document that contains instructions for building a Docker image.

Example of dockerfile for web server

Docker Hub: It is a cloud-based registry service for Docker images. It allows users to store, share, and deploy Docker images.

●A Docker container is a runnable instance of a Docker image.

●A Docker image is a lightweight, standalone, executable package of software that includes everything needed to run an application:

●A Docker volume is a directory or file that is shared between a Docker container and the host machine.

 


 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

G01:Client Server Architecture

  G01 Client Server Architecture A central server (host computer) serves as both the source of service requests and the destination for ...