Unit 2 (2)
Unit 2 (2)
Linux
Linux is a free, open-source operating system (OS) based on Unix.
Multi-User System
Multiple users can access and use the system simultaneously.
Multi-Tasking
It efficiently handles multiple processes at the same time.
Portability
Linux can run on various hardware platforms with minimal
modifications.
Security
Built-in security features like file permissions, user authentication,
and firewall support.
Unit 2 1
Servers & Web Hosting
Linux powers a majority of web servers worldwide due to its
reliability, security, and ability to handle high traffic efficiently.
Popular server solutions like Apache and Nginx often run on
Linux.
3. Once the download is complete, run the installer and follow the
on-screen instructions to install VMware Workstation Player on
your Windows 11 machine.
Unit 2 2
2. Save the ISO file to a location on your computer where you can
easily find it later.
Step 3 : Create a New Virtual Machine in VMware
Workstation Player
1. Open VMware Workstation Player and click on Create a New Virtual
Machine .
Browse to locate the Ubuntu 24.04 LTS ISO file you downloaded.
7. Set the maximum disk size for the virtual machine. A minimum of
25 GB is recommended.
13. Click Close to save the hardware settings and then click Finish to
complete the virtual machine setup.
15. The virtual machine will boot from the Ubuntu ISO file. Follow the
on-screen instructions to start the installation process.
Unit 2 3
User management in Linux is the process of creating, modifying, and
deleting user accounts and groups to control access to system
resources.
Regular Users
Managing Users
Creating Users
Add a New User
Unit 2 4
sudo passwd username
Modifying Users
Change a User’s Username
Deleting Users
Delete a User Without Removing Home Directory
Unit 2 5
sudo userdel username
Secondary Group
Delete a Group
Unit 2 6
sudo groupdel groupname
cat /etc/passwd
groups username
id username
cat /etc/group
last username
ls -l file.txt
Unit 2 7
Change File Permissions
su - username
Unit 2 8
It provides essential services such as process management, memory
management, file system handling, device management, and system
calls.
Process Management
Handles process creation, scheduling, and termination.
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid = fork(); // Create a child process
if(pid>0)
{
printf("Parent Process, PID : %d\n",getpid());
}
else if(pid==0)
{
printf("Child PID : %d, Parent PID : %d\n", getpi(), getppi
d());
}
else
{
print("Fork Failed\n");
}
return 0;
}
#include <stdio.h>
#include <unistd.h>
Unit 2 9
int main()
{
printf("Befor exec()\n");
execlp("ls","ls","-l",NULL); //Execute 'ls -l' command
printf("This line will not execute if exec() succeeds\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Process is running...\n");
exit(0); // Terminate the process
}
Killing a Process
Unit 2 10
ps aux | grep process_name
jobs
Unit 2 11
bg %1 # Resume job 1 to the background
Problem Statement
Steps to Solve
renice 10 -p 4567
Problem Statement
Solution
Steps to Solve
Unit 2 12
ps aux | grep unresponsive_program
kill 6789
kill -9 6789
Confirm termination :
Problem Statement
How can the user continue using the terminal while keeping
the process running?
Solution
and bg .
Steps to Solve
./long_running_script.sh &
Unit 2 13
jobs
fg %1
bg %1
Usage
free -h
Output
Unit 2 14
buff/cache → Memory used for buffering and caching.
Additional Options
Output
swap (si,so) :
io (bi,bo) :
cpu (us,sy,id,wa,st) :
Unit 2 15
id → Idle CPU.
Additional Options
Output
Header Information
PR → Priority.
Unit 2 16
COMMAND → Name of the running command.
Sets Memory Usage Limits for Users → ulimit
Usage
ulimit -a
Output
Unit 2 17
Feature User Process System Process
Key Functions
File Creation
Deletion
Access Control
Mounting
Commands
ls → Lists files and directories.
Unit 2 18
Feature Kernel-Level Services System-Level Services
Process scheduling,
SSH, FTP, logging, web
memory paging, file
Example Services servers, firewall,
system operations,
cronjobs.
device drivers
systemcl, crontabm netstat,
Example Commands ps, kill, df, free, mount
tail -f /var/log/syslog
Grep Command
Grep stands for Global Regular Expression Print.
We can use grep anywhere like with files, searching for file, directories
etc.
Case 2
To search everything except given pattern/keyword.
Case 3
To print how many times (count) given keyword present
Case 4
Unit 2 19
To search for exact match of given keyword in a file.
Case 5
To print the line no. of matches of given keyword in a file.
Case 6
To search a given keyword in multiple files.
Case 7
To suppress file names while searching a given keyword in
multiple files.
Case 8
To search multiple keywords in a file.
Case 9
To search multiple keywords in multiple files.
Case 10
To only print file names which match given keywords.
grep -l "keyword" *
Unit 2 20
Case 11
To get the keywords/patterns from a file and match with another
file.
Case 12
To print the matching line which starts with a given keyword.
Case 13
To print the matching line which ends with a given keyword.
Case 14
To search a keyword in all 100 files in a directory (dirA).
Case 15
We can use egrep command for multiple keyword search.
Case 16
To search but not print on terminal or to suppress error messages.
Unit 2 21
Install the necessary packages.
cd /usr/src
sudo wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.8.t
ar.xz # Replace with latest version
sudo tar -xvf linux-6.8.tar.xz
cd linux-6.8
Unit 2 22
Once the kernel is compiled, install the modules.
sudo reboot
uname -r
Unit 2 23