Sei sulla pagina 1di 12

Unit - 4

Process
Running state of any program is called as process. There can be 5 states of any process.

•New – The process is initialized. Or created.

•Ready - The process is waiting to be allocated to a processor comes to this state immediately
after it is created. All ready processes keeps waiting for CPU time to be allocated by O.S. in order
to run.
•Run - Instructions are being executed. When a process gets a control from CPU plus other
resources, it starts executing.
•Suspend - These processes lacks some resources other than the CPU. Such processes are
normally not considered for execution until the related suspending conditions is fulfilled.
•Terminate - When a process finally stops. A process terminates when it finishes executing its
last statement.

Process State Diagram

In Unix there can be two kind of processes.

•Foreground process
•Background process

Foreground Process - The processes which are running at the


command prompt is called as foreground processes. These
processes can run one at a time.
Background – In unix multiple processes can be executed at the
same time putting jobs in background. This kind of process run at
the backgound of Unix System
e.g. lp file1 &

Process Attributes

•Process ID –
-Every process has an associated process id (pid)
-Pid is a 32 bit unsigned integer, whicg usually ranges from 0 to 32767

-Every process on the system has a parent with exception of PID -1 (init process)
- init process run around all the time, its responsibility is initialization , booting of the system.
- it is parent of all the processes running in Unix.
- init is end when system is shutdown

Jobs of System Administrator


Unix is based on centralized computing environment and according to the working
environment there are two kind of users in Unix.

-End User
-Administrative User

End user is a user who works on dumb terminals and totally depend on the permissions or
environment allotted by administrator.

System Administrator - is a person who is responsible for the management of the entire
system. The whole system management is usually entrusted in multi-user OS to a single
person, called system administrator or super user. Having immense powers. The success
and stability of any unix O.S. depends on the effectiveness of the System administrator.
There are following responsibilities of S.A.
1. User management

2. Disk Management – status of the disk, partitioning etc.


3. System accounting – who is existing who is not.
4. Booting of OS -
5. Shutdown of OS
6. Mounting of new file system
7. Performing backups. – keep back up of file system
8. Security of the system – manage all level of security like user/password , permissions etc.

FILE SYSTEM
Every file system is organized into a sequence of blocks of 256 or 512 bytes.
Commonly there are 4 block in file system –

-Boot block
-Super block
-i-node block
-Data block

Boot Block – containing a small program called bootstrap loader. This is loaded into memory
when the power is on and then it loads kernel into memory.
Super block – contain global file information about disk usage and availability of data blocks and
inodes.

It contains –
-Size of the file system
-Length of disk block
-Last time of updation
-The no. of free data blocks
-No of used data blocks etc.

Inode Block – Every hard disk is organized into blocks where all data reside. Even though the
blocks are numbered consequently. But it is very rear that the data of a file arranged in
contiguous order always it is in scatter form throughout the disk, Therefore it is obvious that
the addresses of all its blocks have to be stored. These addresses are available in the form
of a linked list in the inode. It is maintained individually for each file. Each inode is accessed
by a no. called as i-number, which references the position of the inode in the list.
Inode contains –
-File type (ordinary, directory or special)
-No. of links

-Owner
-Group
-File mode (permissions)
-No. of bytes in the file.
-Data and time of last modification
-An array of 13 pointers to the file. Etc.

Data Block – contains two type of blocks each block assuming of size 256 bytes.
-Direct blocks
-Indirect blocks
There are 13 entries in the inode table containing the addresses of up to 13 disk blocks.
-The 1st 10 addresses are simple enough. They contain the disk addresses of the 1st 10 blocks of
the file. Called as direct blocks
-If file exceeds 10 blocks , 11th block used. This is called as single indirect block , which contains
the address of another direct block block up to 256.

Size=256*(10+256)
-If the size exceeds then 12th entry is used, called as double indirect block, which addresses up to
256 single indirect blocks.
Size = 256*(256*(10+256))
-13the is called as triple indirect block which contains 256 double indirect block.

Finally the max size in Unix file system is ~ 17 GB but actual limit of 32 bit Unix is ~ 2GB.

MOUNTING AND UNMOUNTING of FILE SYSTEM

All file system once created then treat as separate entities with its own tree structure and
root directory. These file system can be unite to become a single file system at the time of
booting. The root becomes main file system. This process of attaching new file system with
unix file system is called as Mounting. The point at which this linkage takes place is called
as mount point.

mount – this is a command used to mount new file system to the root.

# mount <name of the file system> <new file system directory>


e.g attach oracle file system with root.

# mount /mnt /oracle

unmount – to de attach file system from root.


# unmount <file system directory>

# unmount /oracle

Communication – unix provides self networking environment. In which any user can
share information with others. There are certain commands to communicate with other
users by sending messages.
There are two types of communication commands –
-On-line communication – in which it is required that both users sender and receiver should be
login.

a) mesg – this is used to check whether user has permission of online communication or not.
User can change permission also –
$mesg y - set permission
or
$mesg n - revoke permission

-Write – used for online communication.


$write <receiver login>
c) Talk – used to send online messages
$talk <username>

2. Off-Line communication – in which it is not necessary that receiver should be login. The
message is stored into mailbox.

Mail – this command is used to send message as well as receiver can receive or check
messages in mailbox.
sending mail –
$ mail <receiver login>
subject :
-----------
^d
Receive mail –
$ mail – will open mailbox and display &(mail prompt)

&1 - show 1st message of mail box


&r2 - will give reply to 2nd message.
&d1 - delete message 2
&q or &exit - Exit mailbox
&s <file> - save current message into file

b) Pine (Program for Internet News and Email )– is an electronic mail system .used to sending,
reading, and saving Internet e-mail and news-group messages. Main menu is as follows -
Process of Booting
Booting includes process of reading and copy of kernel program into main memory. It
include following steps –
-Power ON
-Executes Boot strap loader program from ROM.
-Perform checking of hardware, testing of main memory and other resources.
-Loading of kernel into main memory. It uses init process with pid -1 and this becomes parent of
the all shell.

Modes – 2 modes

-Single user Mode


-Multi user mode.

We can change mode of the system by using init –

States of init –

State Meaning
0 shutdown
1 Administrative state
S Pure single user mode in which all multiuser file system
unmounted.
2 Multiuser mode
3 Remote file sharing state
6 Stop and restart

Shutdown
-Notify user that system is going down.
-Send signals to all running process to terminate normally.
-Unmount all file systems.
-Update Global file system information.
-Notify user to switch off or reboot.

# shutdown –g <time>
# init 0
# init 6

Backup and Recovery


Protection of information is the most important factor in any organization because the
amount of time and energy spent in gathering information is more valuable. There can be
many reason from the damage or loss of data. Like the bugs in software may corrupt data,
system calls can delete data, wrong command can delete data, hackers can corrupt data
etc. Backup is a facility which allows administrator to save a file system from these
conditions.

cpio – used to gather files and directories by name and copy them to a backup medium.
Switches –
I Input (restore)
O output (backup)
e.g. take backup of current directory contents into floppy.

#cpio –o >/dev/fd0

Restore file again into original position into hard disk.

# cpio –I </dev/fd0

tar – used to copy into a magnetic tape and restore back from there to current directory.

-c copy or backup
-x restore

# tar –c /dev/rmt0 (backup)


#tar –x /dev/rmt0 (restore)

Daemons – is a background process that performs a specific function or activity. They are
processes which are not attached to any terminal. Most of them start at booting and end
with shutdown.

There are 2 types of daemon


•User daemon – defined by user
•System daemon – defined by system itself like init. It is a background daemon which loads
kernel into memory at the tome of booting.
User daemon –
Cron is used to create or excute user daemon. The cron scans the crontab file. Contents
in crontab should be in following format –

Hours min day month weekday command

e.g. 17 00 * * 1-3 init 0


i.e at 5 pm the system will automatically shutdown for all months Monday to Wednesday.

Security in Unix –
Security is an important concern for UNIX OS to protect it from unauthorized users and to
protect user’s resources, without impending authorized users. These security capability
have provided a degree of protection. There are main 3 levels of security provided in Unix
OS.
•User and password – This is a 1st level of security which is necessary to interact with the
Unix OS> for working with the Unix user should have valid username i.e. login and password.
There are 2 user files which keep all the information related with users. /etc/shadow and
/etc/password. These files are used by the login program to authenticate users and to setup their
initial work environment.
create useraccount –
useradd – used to create user login
-u userid
-g group name
-c comment

-d home directory
-s shell path
#useradd <userid> <group> <comment> <homedirectory> <shell> <username>
# useradd –u201 –gstudents –c “student” –d /home/user1 –s /bin/sh user1

Set or Change password –

Passwd – is used to change or set password.

# passwd
Old password :
New password :
2. Setting of Permissions
This is the 2nd level of security. Through which user can protect his files and resources by
changing its permissions. User can change permissions in 2 ways -

•Using chmod command- this is a utility which is used to change the permission of any file and
directory in respect of all three users – owner, group and others.
example – in file test owner has r,w,x, group has r,w, and other has only r permission
$ chmod 764 test

•Using umask command – this is a utility used to change default permission of shell.
example – user wants to set default permission as –rwxrw-r-
$ umask 011
3. Encryption and Decryption
This is 3rd level of security. With this user can keep some of his file confidential, so that any
unauthorized user including administrator cannot read them. While transferring files from
one place to another place user can encode or encrypt contents of file by using a key. The
contents will be converted into cipher text. Now these contents can be accessible only if
receiver know the key of encryption.

Process of encryption –
Using crypt command –
syntax –
$ crypt <key> <file> <output file>
Example
$ crypt dit test file1.enc

Process of Decryption –
Using crypt command
Syntax –
$ crypt < <encrypted file>
Example –
$ crypt file1.enc
Key : test
Command for User Management
•Create user account –
Command – useradd
Syntax –
$ useradd –u <uid> -g <grp name> -c<“description”>
- d <path of home directory> -s <path of shell> <name of user>
Example –
$ useradd –u 210 –g dit –c “student acc” –d /home/mca –s /bin/sh mca

•User account modify –


Command – usermod
Syntax –
$ usermod –switch <username>
Example –
$ usermod –s /bin/ksh mca

3. Delete user account –


Command – userdel
Syntax –
$ userdel <name of user>
Example –
$ userdel mca

Commands of Disk Management

df – called as Disk Free. It reports the amount of free space available on the disk.
Syntax - # df <file system>
Example- # df /dev/fd001

du – called as Disk Used . It reports amount of disk used in the file system.
Syntax - # du <file system>
Example - # du /dev/cd001

gzip and gunzip – these utilities are used to create compressed files and vice versa.
Syntax - # gzip <filename>
Example - # gzip file1
Output – file1.gz file will be created.

Syntax - # gunzip <compressed filename>


Example - # gunzip file1.gz
Output – file1 original file will be created.

fsck() – it is system call called as File System Checking. It used by the system administrator after
abnormal shutdown of the system. It is used to check file system at the time of booting for
corrupted block to repair them and update super block data according to data block. Like
free disk, used disk etc.
Example - #fsck /dev/fd001 // check floppy disk
# fsck // check current file system

Common System calls

•fork() – A process is a program in execution. At the lowest level a process is created by fork()
system call. A fork() creates a separate, but almost identical child running process.
The process which runs fork() system call is called parent process and the process
that create through fork() system call called as child process. These two processes will have
same environment, same user, same group and same priority , but there process id will be
different.
Example –
main()
{
int r ;
printf (“Fork call”);
r=fork();
printf (“\ the process id %d and return value is %d “, getpid(), r);
execl (“bin/echo/”, “echo UPTU LKO”, “ “, 0);
}

•nohup() – this system call is called as no hang up. In general behavior in the operating system
when parent process dies its all child processes also dies. To overcome this behavior there is a
system call nohup() is used.
“nohup() permits the execution of the process even after the user has logged out or
shell is killed”

Example - $nohup lp f1 &

when shell is closed or killed if its child i.e. lp process is alive then it will be reassign new pid
and transferred to init. Init will take care of lp till it is not finished.

Zombie Process
Zombie process is also called as defunct process. It is a process which has been completed
but it entry in process table is still existing. Usually when any process end in Unix, all
resources allocated to it is automatically deallocated, and entry in process table is removed.
But zombie process is a kind of defective process or bug for which after completion process
table entry still exist. To remove this entry parent has to send a signal SIGCHLD to server,
which identify that this process has to be terminated from process table.

Orphan Process
Orphan is a child process for which parent is dead. This kind of process can be dangerous
for system because they usually float here and there in the system. To handle these child
processes init (process of server) adopt these processes by assigning new process id (this
is called as reparenting). Init will handle this child process till the completion of the process.
Export command
“this is command which is used to export variable of parent shell into child shell”
Generally in unix when we work in a shell any variable declared in the shell is not accessible in the
child shell.

Parent shell
$ x=10
$ sh
Child Shell
$ echo $x
-
To access the value of parent shell variable in child shell, use export command in parent shell

Parent shell
$ x=10
$ export x
$ sh
Child Shell
$ echo $x
10

But if user make changes into the value of variable in child shell. The
changes into variable value will not be reflected into parent shell.

Child shell
$ echo $x
10
$ x=15
$echo $x
15
$ exit
Parent shell
$ echo $x
10

Effects of Permissions on Directory and Files


Effect on Directory
User
Read (r) The account owner can list the files in the directory.
Write (w) The account owner can create or delete files in the directory.
Execute (x) access files in that directory by name (such as Web page files).
GROUP
Read (r) Everyone in the designated group can list the files in the directory.
Write (w) Everyone in the group can create or delete files in the directory.
Execute (x) Everyone in the group can change (cd) into the directory and access
files in that directory by name (such as Web page files).
OTHER
Read (r) Anyone can list the files in the directory.
Write (w) Anyone can create or delete files in the directory.
Execute (x) Anyone can change (cd) into the directory and access files in that
directory by name (such as Web page files).
Effects of Permissions on Directory and Files
Effect on Files
User
Read (r) The account owner can read the file. .
Write (w) The account owner can modify or delete the file. .
Execute (x) The account owner can run the file as a program
GROUP
Read (r) Everyone in the designated group can read the file.
Write (w) Everyone in the group can modify or delete the file
Execute (x) Everyone in the group can can run the file as a program.
OTHER
Read (r) Anyone can read the file.
Write (w) Anyone can modify or delete file.
Execute (x) Anyone can run the file as program

Directory Entry Table


Every directory in Unix contains a table with it called as Directory entry table . This table
consists of two columns :
1. File name
2. inode number
•Filename : this column contains names of all files, in the ditectory
•Inode number : contains corresponding inode number of each file.

Whenever any user wants to access a file in Unix , filename will be searched into the
Directory entry if filename is found then only file can be accessed.

Inode Table
Every file in Unix contains a unique identification number called as inode number. Which
further contains number of information about the file.
the following information is stored into inode of a file :
- size if the file
- Permissions to file
-Type of file
-Links of file
-Owner of file
-Group of file
-Date and time of last modification
- Address of the file
Etc.
If any time user want to see the details files with inode number he can give :
$ ls -li

Relation between inode table and Directory table

If any time user wants to access or open a file in Unix he use to specify name of the file
wants to open.
Example :
$ Cat file1
-This file name is searched into the directory entry table, if file name is exist, then inode
number is pick from the table.
-This node number is searched into the inode table, if inode number is found in the table,
then from inode table corresponding address is picked.
-From that address file can be accessed

Similarly if any time user creates a file in Unix then :


Example : cat>file1

-File name will be searched into the directory entry table if file name is already exist then file
cannot be created.
-If file name does not exist then, kernel will allocated memory for file.
-Inode number will be allocated to file.
-Inode entry will be created in the inode table
-Finally directory table will be updated.

Potrebbero piacerti anche