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

Unit 4 & Unit 5

Unit 4 of the UNIX/Linux operating system course covers the UNIX file system including the boot block, super block, inode table, and data blocks used for storing and accessing files. It also covers UNIX tools and utilities like pipes, filters, and process control system calls. Process management is also discussed including process state, context, scheduling, and commands. Unit 5 covers system administration topics like user privileges and security as well as shell programming using variables, parameters, conditional statements, and simple programs.

Uploaded by

ARVIND H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views

Unit 4 & Unit 5

Unit 4 of the UNIX/Linux operating system course covers the UNIX file system including the boot block, super block, inode table, and data blocks used for storing and accessing files. It also covers UNIX tools and utilities like pipes, filters, and process control system calls. Process management is also discussed including process state, context, scheduling, and commands. Unit 5 covers system administration topics like user privileges and security as well as shell programming using variables, parameters, conditional statements, and simple programs.

Uploaded by

ARVIND H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 71

Unit 4 & unit 5

UNIX / LINUX OPERATING SYSTEM


UNIT 4: Unix File System, Tools & Utilities and Process Management
History; Features; Architecture; File system: Boot Block; super block; inode table; data block; storing and
accessing files; directory and file related commands.
Special Tools and Utilities: Filters process; pipe and pipeline; process control; FORK; EXIT; WAIT & EXEC
system call; Unix system calls and Library functions.
Process Management: Process state; data structure of a process; user v/s kernel mode; context of a process;
background processes; process scheduling; process terminating and examining commands.
 
 
UNIT 5: System Administration and Shell Programming
User & supervisor privileges & facilities; accessing the file system; security issues Secondary storage
management
Shell Programming: C Shells; shell variables; parameter shell commands; if; while; until; for; break; continue
and simple programs. Unix System Communication Introduction: write; read; wall; mail commands.
Unix Architecture
Features of Unix
 Multi user
 Multi Tasking
 Building Block
 Tool Kit
 Pattern Matching
 Programming facility
 Documentation
PWD
Boot Block
 Blocks on a Linux (and often a Unix) file system are 1024 bytes in
length, but may be longer or shorter. The blocks are normally a
power of 2 in size (1024 is 2 to the 10th power). Some systems use
512 bytes (2 to the 9th) but 2048 and 4096 are also seen.

 A boot block may contain the bootstrap code that is read into the
machine upon booting.

 The first few blocks on any partition may hold a boot program, a
short program for loading the kernel of the operating system and
launching it. Often, on a Linux system, it will be controlled by LILO or
Grub, allowing booting of multiple operating systems. It's quite
simple (and common) to have a multiple boot environment for both
Linux and a flavour of Windows.
Super Block
 A superblock describes the state of the file system:
how large it is;
how many files it can store;
where to find free space on the file system;
who has ownership of it

 A superblock is a record of the characteristics of a file


system, including its size, the block size, the empty and the
filled blocks and their respective counts, the size and
location of the inode tables, the disk block map and usage
information, and the size of the block groups.

.
I node Block
Internal representation of a file is called an "inode" (contraction of term - index node) which
contains all the required information and description of the file data and its layout on disk. Inodes
resides on the disk and the kernel reads them into an into memory which we can call as in-core
inodes. Disk inodes contains the following information:

 - File access permissions and time (last access / modified etc.)
 - File ownership information.
 - Type of the file (regular / directory / block special / pipe)
 - Number of links to the file
 - File size and organization on disk (the file data may spread across several different and far-
spaced disk location)

The In-core copy of inodes contains all of the above information, but it also contains the
following additional information:

 - Status (locked / process is waiting for it to become unlocked / in-core copy has been modified
and thus differs from the copy on the disk / mounted)
 - Logical Device number of the file system
 - Inode Number. Since inodes are stored in a sequential manner on the disk, the kernel uses an
identifier of that array to refer to its in-core copy.
 - Pointer to other in-core inodes. Kernel maintains a hash queue of inodes according to the
logical device number and the inode numbers. Kernel also maintains a list of free inodes.
 - Reference count which indicates the number of instances of the file that are currently active.
Data block
 data blocks - blocks containing the actual contents of
files
 The Unix file system allocates data blocks (blocks
that contain a file's contents) one at a time from a
pool of free blocks.
 Unix uses 4K blocks. Moreover, a file's blocks are
scattered randomly within the physical disk.
Storing and accessing files
vi, gedit, touch (commands)
Types of unix file system files
 An ordinary file can contain data, such as text for documents or programs.
Eg image files, binary exe files

 A link is not a kind of file but instead is a second name for a file. With a
link, only one file exists on the disk, but it may appear in two places in the
directory structure. This can allow two users to share the same file. Any
changes that are made to the file will be seen by both users.

 Hard links can be used to assign more than one name to a file, but they
have some limitations. They cannot be used to give a directory more than
one name, and they cannot be used to link files on different computers.

 symbolic link is a file that only contains the name (including the full
pathname) of another file.
 Symbolic links can be used to assign more than one name to a file or
directory, or to make it possible to access a file from several locations.
Ls prefix eg Ls- l
• Copying cp command
• Removing rm command
Absolute mode (Numeric mode)
Chmod (Absolute)

764' absolute code says the following:


 Owner can read, write and execute
 Usergroup can read and write
 World(other) can only read
Chmod (symbolic)
Interprocess communication
• Interprocess communication (IPC) is a set of
programming interfaces that allow a programmer to
coordinate activities among different program processes
that can run concurrently in an operating system.
• This allows a program to handle many user requests at the
same time. Since even a single user request may result in
multiple processes running in the operating system on the
user's behalf, the processes need to communicate with each
other
System Utility
• ls
• cp
• grep
• wc
• more, rm
• Mkdir
• mv
Grep cmd
The uniq command in UNIX is a command line utility for reporting or
filtering repeated lines in a file. It can remove duplicates, show a count of
occurrences, show only repeated lines, ignore certain characters and
compare on specific fields. The command expects adjacent comparison
lines so it is often combined with the sort command.
Cut , colrm , paste, join command

• Cut selects particular column or fields from files


• colrm – deletes one or more columns
• paste – create new tables or files gluing
together files
• join - command joins together two existing files
on the basis of a key field that contains entries
common to both of them.
• join matches lines according to the key field
Cut , colrm , paste, join command
Sudo
• sudo command to allow you to temporarily perform the
superuser task you need to. This will return you to normal
user privileges upon completion of the task, and avoid
involuntarily leaving a user with root privileges. Specific users
can also be granted access to specific limited root-level
commands used for system administration functions (which
are logged for security purposes) using s
Sudo .
Su
• The su command allows you to run a shell as
another user.
• Syntax:
su <username>
• Example:
Pipes
A series of filter commands can be piped together using the pipe symbol: ‘|’. When two
commands are piped together, the stdin of the second program is read from the stdout
of the first program. This creates a powerful mechanism for running complex
commands quickly.
Unix process creation
• process equivalent to task, as in multiprocessing or
multitasking
• A new process is created by the fork call
• Child and parent are identical
– child returns a 0
– parent returns nonzero
• Both parent and child execute next line
• Often the child executes an exec
– creates a brand new process in its space
• Parent can execute a wait
Ps Command

The ps command lists all of the active processes running on the machine. If you use ps
without any options, information is printed about the processes associated with your
terminal.
Ps command options
Process Types

• Foreground Process (eg :ps)


- Run by executing a command at the command line
- the command is executed immediately The system will devote
whatever resources are necessary to complete the process, and when
the process is completed-the shell prompt will appear, indicating that
the process is complete
• Background process ( eg $ls ch*.doc & )
- The process is scheduled for execution at a later time when
resources are available, according to priorities set by the system
administrator.
• The advantage of running a process in the background is that you can
run other commands; you do not have to wait until it completes to
start another
• The simplest way to start a background process is to add an
ampersand (&) at the end of the command.
Exec
• Fork creates a copy of the parent
• Use exec() to launch another program
– Initiate a program from within a program
– Transforms the calling process into a new process
• Family of functions
– exec, execlp, execle, execv, execvp, execvP
– Front ends to the function execve
execve
• Executes a process in an environment which it
assigns
• Process arguments and the environment are
passed as null terminated arrays of character
pointers
– char *env[] = {“USER=qos”,”PATH=/usr/bin:/bin”, (char *)0 };
– char *args[] = {“/bin/someprog”, “-r”, “-verbose”, (char *)0 };

– execve(args[0], args, env);


execl and execlp
• Creates a new program in the same
environment
• execl requires a fully qualified path
• execlp will use the environment variable PATH
to search for the file
• Takes a null terminated list of arguments
execv and execvp
• Same as execl
– Arguments are passed as a null terminated array
of character pointers
 execv(char * path, char * argv[]) : given the path to the
program and an argument array, load and execute the
program
 execvp(char * file, char * argv[]) : given a file(name) of
the program and an argument array, find the file in the
environment PATH and execute the program
 execvpe(char * file, char * argv[], char * envp[]) given a
file(name), an argument array, and the enviroment
settings, within the enviroment, search the PATH for the
program named file and execute with the arguments
System calls

• System calls in Unix are used for file system


control, process control, interprocess
communication etc. Access to the Unix kernel
is only available through these system calls.
Generally, system calls are similar to function
calls, the only difference is that they remove
the control from the user process
System calls
Library functions
Library functions
• alarm – Sets an interval time to expire after and interval
of seconds duration. This is often used to force return from
a read() function call, or other kernel functions which allow interruption
by the SIGALRM signal. If seconds is zero, any existing interval timers will
be reset.
• Returns alarm returns the number of seconds remaining from a pre-
existing call to the same function, or zero if there was no prior unexpired
alarm interval. No condition is reserved as an error, and the function is
always successful.

IS_INTEGER alarm ( IS_INTEGER seconds );


Ps Command
User vs. Kernel
• Kernel Mode In Kernel mode, the executing code has
complete and unrestricted access to the underlying hardware.
It can execute any CPU instruction and reference any memory
address. Kernel mode is generally reserved for the lowest-
level, most trusted functions of the operating system. Crashes
in kernel mode are catastrophic; they will halt the entire PC.
• User Mode In User mode, the executing code has no ability to
directly access hardware or reference memory. Code running
in user mode must delegate to system APIs to access
hardware or memory. Due to the protection afforded by this
sort of isolation, crashes in user mode are always recoverable.
Most of the code running on your computer will execute in
user mode.
Process Scheduling
• As a time-sharing system, the UNIX system
kernel directly controls how processes are
scheduled.
• User-level commands are available that allow
you to specify when you would like processes
to be run.
Process scheduling
 at
 Cron tab
 Batch Commands

daemon

Priority
 Nice
 sleep
 Wait
 Ps
termination
 Exit
 Kill
Batch Command
• batch will queue the commands to be
executed when the load on the system
permits
• The batch command is especially handy when
you have a command or set of commands to
run but don’t care exactly when they are
executed.
Process priority
• Processes on a UNIX system are sequentially
assigned resources for execution.
• The kernel assigns the CPU to a process for a
time slice; when the time has elapsed, the
process is placed in one of several priority
queues
Nice Command
• The nice command allows a user to execute a command
with a lower-than-normal priority The process that is
using the nice command and the command being run
must both belong to the time-sharing scheduling class.
• You can decrease the priority of a command by using
nice to reduce the nice value. If you reduce the priority
of your command, it uses less CPU time and runs slower
• $ nice −19 proofit ( Reduce 19 priority for process)
Sleep Command
• The sleep command does nothing for a
specified time.
• sleep time
• $ (sleep 3600; who >> log) & provides a
record of the number of users on a system in
an hour. It creates a process in the background
that sleeps (suspends operation) for 3,600
seconds; and then wakes up

You might also like