Operating System Concepts.1

0
Text Example

Operating System Concepts.


# Linux Commands – 2 days

Operating System Concepts

- there are 4 steps to learning an OS:

step-1: user level (basic Linux commands)

step-2: admin level (shell script programming)

step-3: programmer level (introduction to system call programming by using system calls).

step-4: design level / internals


step-1: user level (basic linux commands):


What is Linux?

Q. Why there is a need of an OS? What is a Computer?

- Computer is a hardware/machine, which performs different tasks efficiently and accurately for user.

- there are 4 basic functions of computer:

1. data storage

2. data processing

3. data movement

4. control

- Computer hardware mainly contains : CPU/Processor,

Memory Devices & IO Devices.

- As any user cannot directly interacts with any computer hardware component, hence there is a need of interface between user and hardware, and to provide this interface is the job of an OS.

What is a software?
What is a Program?

- there are 3 types of programs

1. user programs: main.c, slll.java, program.cpp etc...

2. application programs: notepad.exe, ms office, google chrome, calculator, games etc...

3. system programs: programs which are part of an Os i.e. inbuilt programs of an OS.

e.g. kernel, scheduler, memory manager, loader, dispatcher, linker, interrupt handler etc....


Q. What is an OS?

- An OS is system software (i.e. collection of system programs) which acts as an interface between user and hardware.

Kernel => it is a core part/program of an OS which runs continuosly into the main memory and does basic minimal functionalities of an OS.

e.g.

Linux => vmlinuz

Windows => win32krnl.exe / ntoskrnl.exe

- Kernel is like heart of an OS.

- Basic Minimal Functionalities/Core Functions/Kernel

Functions: Process Management, Memory Management,


Hardware Abstraction, CPU Scheduling and File & IO Management.

- to compile a java program :  $javac hello.java => terminal

- to execute a java program $java hello

- to compile c program $gcc -c program.c => program.o (object code)

- to link object code of a program with precompiled

object modules:

$gcc -o program.out program.o => program.out 

- to execute program $./program.out => in Linux $.\a.exe => in windows

- Shell => shell is an application program which acts as a CLI(Command Line Interpreter), which accepts command from user in a text format, interpret it and pass it to the kernel for an execution.

-In Linux there are 2 types of Shell

1. CUI Shell : terminal  e.g. bsh, bash, csh, ksh etc....

2. GUI Shell

- To install an OS onto the computer system means to store OS Software (i.e. collection of thousands of system programs, application programs and utility programs which are in a binary format) onto the HDD.

- Linux Kernel vmlinuz is exists in /boot dir in a binary format.

- While installing Linux we need to format disk by using extended filesystem i.e. we need to create a new filesystem on that partition named as ext filesystem.

- While installing Linux we need to create 2 partitions:

1. swap partition =>

 it is a portion of HDD kept reserved by Linux OS while installtion will be used as a swap area.

- swap area -> portion of HDD used by an OS as an extension of the main memory in which inactive running programs can be kept temporarily => memory managemnt.

- conventionally the size of swap area should be doubles the size of main memory.

2. data partition/root partition ( / ) partition:

in which LINUX OS keeps/stores data in an organized manner or in a hierarchical manner.

- When any user loggedin into the system or opens terminal, system takes user bydefault into the user’s home dir.

- to open terminal =>

way-1: press window key -> enter terminal in search bar and press enter

way-2: cntrl+alt+t

Command Name : pwd 

– print working directory / present working direcitory

- this command prints an absolute path of present working directory.



Command Name : whoami

- this command prints name of currently logged in user into the system on terminal.



Command Name : ls – list dir contents

- contents of dir file are names of sub dir’s and files in it. 

$ls - ls command displays contents

$ls => bydefualt it displays contents of cur dir in a columnwise alphabatically sorted manner.

$ls -1 => it displays contents of cur dir per line one entry in alphabatically sorted manner.

$ls -s => total no. of data blocks allocated for file to store actual data into the disk.

usually size of physical data block = 512 bytes.

Size of logical data block = multiple of 512

512 bytes / 1024 bytes / 2048 bytes / 4096 bytes



$ls -l ditpath

 => display contents of dir in a long list format

In output of ls -l command: total n 

n = sum of total no. of data blocks allocated for files

listed below.

- First char of first column indicates type of a file

- In Linux/UNIX based operating system, there are 7 types of files:


1. regular file ( - ) : all text files, source files, image files, audio files, video files, pdf files etc.... considered as a regular file.

2. directory file ( d )

dir file is a special type of file whose contents are names of its sub dir’s and files.

3. character special device file ( c )

4. block special device file( b )

5. linkable file ( l ) : it like short cut files in Windows, to access deeply located file more frequently linkable file can be used.

6. pipe file ( p )

7. socket file ( s )

- pipe file and socket file is used inter process communication.

- Everything treated as a file, from System point of view all devices treated as a file

- In Linux/UNIX based operating systems devices can be catagorised into two categories:



1. character devices => devices from which data gets transferes char by char i.e. byte by byte

e.g. keyboard, monitor, printer etc...

Linux/UNIX based OS treats all char devices as char special device files.

- When an execution of any program is started, an OS bydefault opens 3 files for it:

1. stdin => standard input buffer which is associated with standard input terminal/device keyboard i.e. console

input.

2. stdout => standard output buffer which is associated with standard output erminal/device monitor i.e. console

output

3. stderr => standard error buffer which is associated with standard output terminal/device monitor i.e. console

output.

2. block devices => devices from which data gets transferes block by block i.e. sector by sector

e.g. all storage devices

Linux/UNIX based OS treats all block devices as block special device files.

- next 3 chars of first col after type of file indicates access perms for user/owner of that file, then next 3 chars indcates access perms for group members and last 3 chars indicates access perms for others.

Command Name : clear – to clear the screen

- clear command clears the screen and takes cursor to the left top, and blinking cursor resides command prompt symbol ($), indicates shell is waiting for the user to

enter next command.

- to clear the screeen => short cut key [ cntrl + l ]

Command Name : top

- to display information about running programs/processes.

- top command is like a s task manager in Windows.

- press key q to quit top

- all linux commands are case sensitive

Command Name : uname

- to display system information

$uname -a => to displlay all system information

$uname -v => to print version of system


Command Name : cd – change dir

$cd , whereas dirpath may any absolute path or relative path of a dir file.

- this command is used for navigation throughout filesystem, i.e. by using cd command we can go from one location any other location.

- filesystem => it is a way to store data onto the disk/partition in an oragnized manner so that it can be accessed by the system efficiently.

- Shell metacharacters:

/ (root dir)

~(cur logged in user’s home dir

. (current dir)

.. ( parent dir)

$cd / => goto the root dir

$cd ~ => goto the user’s home dir

$cd . => goto the cur dir / remains in a cur dir

$cd .. => goto the parent dir of cur dir

$cd - => goto prev accessed dir

Mumbai => Pune => Satara => Karad => Kolhapur => Banglore


Command Name : mkdir

- command used to create a new dir / directories

$mkdir

$mkdir -p one/two/three

- -p option can be used with mkdir command to create a dir hierarchy.

- dir by the name one gets created as a parent dir in a mentioned dir, then sub dir by the name two gets created inside dir one, and sub dir by the name three gets created inside dir two.

Command Name : rmdir

- we can delete only empty dir by using rmdir command.

Command Name : rm – remove file/files

- rm command is to used to delete/remove file/s, it also used to remove/delete non-empty dir with -R option $rm -R dirpath

- it deletes first contents of all sub dir’s and files of the dir recursively in it and then it deletes dir. 

+ physical data block size = 1 sector = 512 bytes

- at hardware level head can access data from 1 sector at a time i.e. 512 bytes of data at a time.

- it can be decided at the time of disk manufacturing. + logical data block size => it can decided at the time of formatting i.e. creating a new filesystem. 

- it must be in a multiple of 512 bytes, filesystem can access data as per logical data block size.

[ a ]

[ b c d e f ] - grp

[ g ]

[ h ]

[ i ]

[ j ]

cur logged in user => d

-rwxrw-r-- file.txt

user/owner => d

group members => b c e f

others => a g h i j

second col in a ls -l command => link count => no. of links having for that file in a filesystem => no. of ways

which file can be accessed.

- bydefault link count of a regular file = 1

- bydefault link count of a dir file = 2

when we createa a new dir one link gets created into its parent dir and 1 hidden entry gets created inside itself by the name.

- In Linux filename starts with dot ( . ) is considered as a hidden file.

$ls -a => to display all contents of dir including hidder files.

-Process => PCB Process Control Block - pid

- File => FCB/iNode File Control Block – iNode number 

iNode number is an unique identifier of a file in a filesystem.

Post a Comment

0 Comments
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !