Unix M1
Unix M1
➢ The main concept in the unix architecture is the division of labor between two agencies the
KERNEL and SHELL.
➢ The kernel interacts with hardware and shell interacts with user.
➢ The kernel is the core of the operating system- a collection of routines mostly written in C.
➢ It is loaded into memory when the system is booted and communicates directly with the
hardware. User applications (programs) that need to access the hardware, uses the services of
kernel. These programs access the kernel through a set of function called system calls.
➢ Apart from providing support to user programs, the kernel also performs other tasks like
managing system’s memory, scheduling processes, decides their priorities etc. So the kernel
is often called the operating system- a program’s gateway to the computer’s resource.
➢ The shell is the command interpreter, it translates command into action.
➢ It is the interface between user and kernel.
➢ System contains only one kernel, but there may be several shells.
➢ When user enters a command through the keyboard the shell thoroughly examines keyboard
input for special characters, if it finds any, it rebuilds simplified command line and finally
communicates with kernel to see that the command is executed.
➢ For eg,consider a echo command which has lots of spaces between the arguments:
➢ Eg: $echo Sun solaris
In the above example shell first rebuilds the command line i.e. it will compress all extra
spaces, then it will produces output.
Sun solaris
The file and process:
➢ Two simple entities supports the unix system is the file and process.
➢ A file is just an array of bytes and can contain virtually anything.
➢ It is also related to another file by being part of a single hierarchical structure.
➢ Files will be arranged in a hierarchical structure in unix system.
➢ A process is the name given to a file when it is executed as program.
➢ So the process is an time image of executable file.
➢ Process are treated as living organism which have parents, children and grand-children and
are born and die.
The system calls:
➢ Unix system’s kernel, shell and applications are written in C.
➢ There are several commands in the unix system, they uses system call functions to communicate
with kernel.
➢ Eg: Unix command writes into the file using write system call.Open system call can be used to open
the file.
3. Explain basic file types in Unix OR Explain different types of files supported in UNIX. MQP
DIFFERENT TYPES OF FILES IN UNIX OR BASIC FILE TYPES OR CATEGORIES:-
3. Device File:
➢ Device files represent hardware devices in UNIX.
➢ Example: Used for printing files, installing software, or backing up data.
➢ Device files are stored in the /dev directory.
➢ A device file does not store data but acts as an interface to interact with hardware devices.
➢ Types of device files:
i) Character Device Files:
➢ Represent hardware devices that transfer data character by character.
➢ Used for devices where data is read/written in a continuous stream.
➢ Eg:- Keyboards, mice, terminals, and serial ports.
➢ Data is transferred one character at a time without buffering.
➢ Typically found in the /dev directory (e.g., /dev/tty1 for a terminal).
ii) Block Device Files:
➢ Represent hardware devices that transfer data in blocks (fixed-size chunks).
➢ Used for storage devices where data is accessed randomly.
➢ Eg:- Hard drives, USB drives, and CD-ROMs.
➢ Data is buffered, improving performance for large transfers.
➢ Typically found in the /dev directory (e.g., /dev/sda for a hard disk).
➢ These files are crucial for organizing the file system and interacting with hardware devices
efficiently
Internal Commands
➢ Built into the shell itself.
➢ Do not exist as separate executable files.
➢ Faster to execute as they run directly in the shell.
➢ Example:
➢ $ type echo
➢ echo is a shell builtin
➢ Here, echo is an internal command.
External Commands
➢ Independent executables stored in directories like /bin or /usr/bin.
➢ Found and executed by the shell using the PATH variable.
➢ Slower to execute compared to internal commands.
➢ Example:
➢ $ ls
➢ /bin/ls
➢ The ls command is an external command.
Shell Precedence
➢ If a command exists as both internal and external, the shell prioritizes the internal version.
➢ Example: The echo command is both internal and external, but the shell uses its internal
version.
Command Arguments
➢ Commands can accept arguments in different forms:
➢ Expression: Example in grep: grep "pattern" file.
➢ Instructions: Example in sed: sed 's/old/new/g' file.
➢ Program: Example in awk: awk '{print $1}' file.
Example:
➢ Internal Command: cd (Change Directory)
Usage: cd Documents changes the working directory to "Documents."
➢ External Command: ping (Test network connection)
Usage: ping google.com checks connectivity to Google's server.
This classification optimizes shell performance and ensures efficient command usage.
5. What is Parent child relationship? With the help of neat diagram, explain Unix File System
PARENT-CHILD RELATIONSHIP
➢ All files in unix are related to one another.
➢ The file system is organized in a hierarchical structure.
➢ The implicit feature of unix file system is that there is a top directory which is called as root
which serves as the reference point for all files.
➢ Top is represented by a /(front slash).
➢ Root directory(/) has several sub directories under it.
➢ These subdirectories in turn have more sub directories and other files under them.
• Ex: bin and usr are two directories directly under /, while cp and pwd are
subdirectories under bin.
➢ Every file must have a parent and it should be possible to trace the ultimate parentage of a
file to root.
➢ Thus, the home directory in the above figure is the parent for mthomas, while / is the parent
of home and the grand parent of mthomas.
➢ In the parent-child relationship, the parent is always a directory.
• Ex: login.sql is an ordinary file, it cannot have a directory under it.
UNIX FILE SYSTEM
Data is organized into files and files into directories and directories into tree like structure.
i. / : The slash / character alone denotes the root of the filesystem tree.
ii. /bin : Stands for “binaries” and contains certain fundamental utilities, such as ls or cp, which are
generally needed by all users.
iii. /boot : Contains all the files that are required for successful booting process.
iv. /dev : Stands for “devices”. Contains file representations of peripheral devices and pseudo-devices.
v. /etc : Contains system-wide configuration files and system databases. Originally also contained
“dangerous maintenance utilities” such as init,
vi. /home : Contains the home directories for the users.
vii. /lib : Contains system libraries, and some critical files such as kernel modules or device drivers.
viii. /media : Default mount point for removable devices, such as USB sticks, media players, etc.
ix. /root : The home directory for the superuser “root” – that is, the system administrator. This
account’s home directory is usually on the initial filesystem, and hence not in /home (which may
be a mount point for another filesystem) in case specific maintenance needs to be performed, during
which other filesystems are not available. Such a case could occur, for example, if a hard disk drive
suffers physical failures and cannot be properly mounted.
x. /tmp : A place for temporary files. Many systems clear this directory upon startup; it might have
tmpfs mounted atop it, in which case its contents do not survive a reboot, or it might be explicitly
cleared by a startup script at boot time.
xi. /usr : Originally the directory holding user home directories,its use has changed. It now holds
executables, libraries, and shared resources that are not system critical, like the X Window System,
KDE, Perl, etc. However, on some Unix systems, some user accounts may still have a home
directory that is a direct subdirectory of /usr, such as the default as in Minix. (on modern systems,
these user accounts are often related to server or system use, and not directly used by a person).
xii. /usr/bin : This directory stores all binary programs distributed with the operating system not
residing in /bin, /sbin or (rarely) /etc.
xiii. /usr/include : Stores the development headers used throughout the system. Header files are mostly
used by the #include directive in C/C++ programming language.
xiv. /var : A short for “variable.” A place for files that may change often – especially in size, for example
e-mail sent to users on the system, or process-ID lock files.
xv. /var/spool : Spool directory. Contains print jobs, mail spools and other queued tasks.
xvi. /var/tmp : A place for temporary files which should be preserved between system reboots.
6. Write the output for the following commands. (THEY CAN EVEN AS THE SAME FOR OTHER
COMMANDS TOO)
i. cal 10 2021
Displays the calendar for October 2021.
October 2021
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
iv. passwd
Prompts the user to change their password.
Changing password for <username>.
Current password:
New password:
Retype new password:
v. who
Displays information about users currently logged into the system.
username tty1 2025-01-18 09:00
username pts/0 2025-01-18 09:15 (192.168.1.10)
. -j vi ___o --
\ n ➔
·e '1
..· . 0./\
,.
@...
r
~ _
... -
~9
\ 4 Q,
\ r- ➔ A- <I c..aa,
) -d)
;~ o
, .... Nnz
Date/
I
+ 1/.. ---)
t"/. nJZ.
-f 1/· y -) ~
f 1/. . -." \
-+
·0,\.a~-
'· ···-·
•
- .P
r cJO : r:J C: o)
/ -o ··
)
Po iwJ
Date/
l
l . \ ,-
I (
0 . f}
~ \ • I
.)
)t (_Q_ cWI\. ()~(r.t: . flit (}-
G\..P-4__ --~
- \I f\£),-,V'
- r\ (j
,
,, ·.,,
..._
(J
/ -) ~
If)
)l ~
- {V\\/
. \ 0