Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Operating system and Basic linux commands, Study notes of Operating Systems

This contains Introduction to the Operating system and some Basic Linux commands along with an explanation for each command and executed snapshots.

Typology: Study notes

2020/2021

Available from 10/14/2022

Adyyyyy
Adyyyyy 🇮🇳

1 document

1 / 57

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1
ANSWER 1:
INTRODUCTION TO OPERATING SYSTEM:
Operating system acts as an interface between computer
system and the user, and helps to communicate with the
hardware. The hardware must provide appropriate mechanism
to ensure the correct operation of the computer system and to
prevent user programs from interfering with proper operation
of the system. Operating system is the software that manages
the computer hardware and provides a convenient and safe
environment for
running programs in
a convenient and
efficient manner. It
acts as an interface
between programs
and hardware
resources that these
programs access (like memory, hard disk and printer). It is loaded in
the memory when the computer or system is booted and running until
the system keeps on running.
FEATURES OF OPERATING SYSTEM:
1. Ease of use/convenience: OS provides users the services to execute the programs in a convenient manner.
2. Efficiency: OS allows the computer system resources to be used in an efficient manner.
3. Ability to evolve: Several new system functions and concepts can be introduced and combined with the best
ideas of the previously existing system to foster effective development.
FUNCTIONS OF OPERATING SYSTEM:
1. Control over system performance: The OS supervises and monitors overall system health which helps
improve system performance. It uses the mechanism of recording the response time between service requests
and system response to have a complete view of the system health and provides important information needed
to troubleshoot problems which can help improve performance.
2. Error detection and handling: It is the task of the operating system to detect any error and malfunctioning
of computer system if it occurs by constantly monitoring the system and to handle it properly.
3. Security: The operating system is responsible for our system security. It protects user data and information
by the use of passwords and other similar techniques. It also prevents unauthorized access to the system.
NAME: ADITI
ROLL No. : 101903527
GROUP: 2CO20
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download Introduction to Operating system and Basic linux commands and more Study notes Operating Systems in PDF only on Docsity!

ASSIGNMENT 1

ANSWER 1 :

INTRODUCTION TO OPERATING SYSTEM:

Operating system acts as an interface between computer system and the user, and helps to communicate with the hardware. The hardware must provide appropriate mechanism to ensure the correct operation of the computer system and to prevent user programs from interfering with proper operation of the system. Operating system is the software that manages the computer hardware and provides a convenient and safe environment for running programs in a convenient and efficient manner. It acts as an interface between programs and hardware resources that these programs access (like memory, hard disk and printer). It is loaded in the memory when the computer or system is booted and running until the system keeps on running. FEATURES OF OPERATING SYSTEM:

  1. Ease of use/convenience: OS provides users the services to execute the programs in a convenient manner.
  2. Efficiency: OS allows the computer system resources to be used in an efficient manner.
  3. Ability to evolve: Several new system functions and concepts can be introduced and combined with the best ideas of the previously existing system to foster effective development. **FUNCTIONS OF OPERATING SYSTEM:
  4. Control over system performance:** The OS supervises and monitors overall system health which helps improve system performance. It uses the mechanism of recording the response time between service requests and system response to have a complete view of the system health and provides important information needed to troubleshoot problems which can help improve performance. 2. Error detection and handling: It is the task of the operating system to detect any error and malfunctioning of computer system if it occurs by constantly monitoring the system and to handle it properly. 3. Security: The operating system is responsible for our system security. It protects user data and information by the use of passwords and other similar techniques. It also prevents unauthorized access to the system.

NAME: ADITI

ROLL No. : 101903527

GROUP: 2CO

4. Memory Management: It is the duty of the operating system to manage the main memory. It keeps a track of the memory (which bytes of memory are used by which user programs) given to different processes and the addresses where memory is free for use. It also allocates memory to different processes when the process requests it and de-allocates the memory when the process has terminated or is performing an I/O operation. In multi programming, the OS decides the order in which process are granted access to memory, and for how long. 5. File Management: All the files in the system are stored in a file system consisting of directories for efficient and easy navigation or usage. These directories may also contain sub- directories or files. The operating system manages all these files, their access permission and their status. It also keeps track of where information is stored, user access settings and status of every file and more… These facilities are collectively known as the file system. 6. Device Management: It is the responsibility of the operating system to manage the all the different devices connected to the system and their communication through the device drivers and keep track of them. Operating system designates a program responsible for every device known as the Input/output controller. It decides the process will get access to different devices and for what duration to ensure effective and efficient allocation, and de-allocates devices when they are no longer required. 7. Processor Management : The OS performs process scheduling, i.e. it decides the order in which processes have access to the processor, and how much processing time each process has. It allocates the CPU(processor) to a process and de-allocates processor when the process is terminated. It also designates a program called traffic controller which keeps track of status of processes. 8. Coordination between other software and users: OS also coordinate and assign interpreters, compilers, assemblers and other software to the various users of the computer systems. 9. Job accounting: OS keeps track of time and resources used by various tasks and users, this information can be used to track resource usage for a particular user or group of user. OPERATIONS OF OS COMMON TO MOST SYSTEMS:

  1. OS allocates memory for the program and loads the program on the allocated memory.
  2. It also loads the CPU registers with control information related to program. The registers maintain the memory locations where each segment of a program is stored.
  3. The instructions provided in the program are executed by the CPU. The OS keeps track of the instruction that was last executed which enables it to resume a program if it had to be taken out of the CPU before it completed execution.
  4. If the program needs to access the hardware, it makes a call to the OS rather than attempt to do the job itself. For example, if the program needs to read a file on disk, the OS directs the disk controller to open the file and make the data available to the program.
  5. After the program has completed execution, the OS cleans up the memory and registers and make them available for the next program. USER SERVICES: Operating System also provides certain services to the computer system in one form or the other.
  6. Program execution 5. Resource allocation
  7. Handling Input/Output operation 6. Accounting
  8. Manipulation of File system 7. Information and resource protection
  9. Error detection and handling

ANSWER 3:

ARCHITECHTURE OF LINUX:

Architecture of Linux operating system can be distributed into several layers as follows:

1. Hardware: Hardware represents the physical components/peripheral devices of our computer like the keyboard, mouse, monitor, RAM, HDD and CPU. 2. Kernel: It is the main part/core of the LINUX based operating system, also known as the heart of the OS- a collection of routines mostly written in C. It is loaded into memory when the system is booted and communicates directly with the hardware. It is also responsible for memory and time allocation for different tasks, scheduling processes, deciding their priorities, keeping track of the processes in progress and for keeping the track of what a user is allowed to do. The kernel is also responsible for preventing and mitigating conflicts between different processes. User programs (applications) that need to access the hardware (like hard disk or terminal) use the services of the kernel, which performs the job on the user’s behalf. In a Unix-like operating sys-tem hides all low-level details concerning the physical organization of the computer from applications run by the user. When a program wants to use a hardware resource, it must issue a request to the operating system. The kernel evaluates the request and, if it chooses to grant the resource, interacts with the proper hardware components on behalf of the user program. In LINUX, the kernel is represented by the file **/boot/vmlinuz.

  1. Shell:** Shell is a command interpreter (translates commands into actions) which allows user to interact with a UNIX system. Key in a word and the shell interprets it as a command to be executed. It acts as a medium between the kernel and the user. Shell is responsible for hiding the complexity of kernel’s working from the user. It takes instruction from the user and gets the required task done from the kernel. It also interprets the output of the task done by the kernel and sends the result to the user. Even though there’s only one kernel running on the system, there could be several shells in action- one for each user who is logged in. 4. Applications: These are the different kind of utility programs which run on the shell of our operating system. These can be like our web browser, text editor, media player, etc. These programs access the kernel through a set of functions called system calls. System Utility: It provides the functionalities of an operating system to the user.

ANSWER 4:

SYSTEM CALL EXECUTION:

Introduction:

UNIX systems implement most interfaces between User Mode processes and hardware devices by means of system calls issued to the kernel. Putting an extra layer between the application and the hardware has several advantages- it makes programming easier by freeing users from studying low-level programming characteristics of hardware devices, it greatly increases system security, because the kernel can check the accuracy of the request at the interface level before attempting to satisfy it, last but not least, these interfaces make programs more portable, because they can be compiled and executed correctly on every kernel that offers the same set of interfaces. All the commands in the UNIX system use a handful of functions, called system calls, to communicate with the kernel. All UNIX system use the same system calls. These system calls are defined in POSIX specification. If an OS uses different system calls, then it won’t be UNIX. The reason why LINUX can’t replace UNIX is that LINUX uses the same system call; LINUX is UNIX. System call is an explicit request to the kernel made via a software interrupt.

Mechanism:

When a User Mode process invokes a system call, the CPU switches to Kernel Mode and starts the execution of a kernel function. The net result of invoking a system call is a jump to an assembly language function called the system call handler. Because the kernel implements many different system calls, the User Mode process must pass a parameter called the system call number to identify the required system call; the eax register is used by Linux for this purpose. There are three general methods for passing parameters to the OS:

  1. Parameters can be passed in registers
  2. When there are more parameters than registers, parameters can be stored in a block and the block address can be passed as a parameter to a register.
  3. Parameters can also be pushed or popped off the stack by the operating system.

Types of system call:

The different types of system call are as follows:

1. Process Management: This kind of system call is used to manage the processes which are occurring on the system. These system calls are needed for process creation, process termination, to allocate and to free memory for processes, etc. Example- 1. fork( ): This system call is used by the parent process to create a new process known as the child process. Until the child process is executing, the parent process is suspended. 2. wait(): The suspension of the parent process automatically occurs with a wait() system call. When the child process ends execution, the control moves back to the parent process. 3. exit( ): This system call is used to terminate a process. We generally use it to stop a process when certain condition is fulfilled. Especially in the multi-threaded environment, this call defines that the thread execution is complete. The OS reclaims resources that were used by the process after the use of exit() system call. 2. File Management: These system calls are used in file manipulation like creating a file, deleting a file, reading a file, writing a file, etc. Example- 1. open( ): This system call is used by process to access a file. It returns a handle that the process can use to access the file. Since read and write use file descriptor as their 1st parameter so to know the file descriptor open() system call is used. 2. read(): This system call is used to read the content from the file. It can also be used to read the input from the keyboard by specifying the 0 as file descriptor. This returns the number of bytes read. 3. write(): This is used to write the content to the file. 4. close( ): This system call is used by a process to terminate access to a file. It tells the operating system that the file is needed no more. 3. Device Management: These system calls are used to read from devices, to write to them, request and release the device, etc. Example- 1. ioctl( ): This system call is used for device specific input/output operations which cannot be performed by usual system calls. 2. read( ): This system call is used to read data from the devices connected with the system. 3. write(): This system call is used to write data to the devices connected with the system. 4. Information Management: This system call is concerned with the handling and sharing of information between the process and the operating system. The operating system also keeps information about the ongoing processes and provides this information through system call. Example- 1. getpid( ): This system call is used to get the process ID of the calling process. 2. alarm( ): There is only one alarm clock per process. While the default action for SIGLARM is to terminate the process, usually we will want to catch this signal. The alarm() function sets a timer that generates the SIGALARM signal. If we ignore or don’t catch this signal, the process is terminated. 3. sleep( ): This system call is used when user wants to halt the current process for some time. It keeps the locks hold on resources till the sleep time is over and again starts the execution of the process. 5. Communication Management: These types of system call are used in inter-process communication. It is also responsible for creation and deletion of communication connection. Example- 1. pipe( ): This system call can be used to connect two processes. One process can be used to write to the pipe and other to read from the pipe. 2. mmap( ): This system call is used to map files and devices to memory. 3. shmget( ): This system call on successful completion returns an identifier for the shared memory segment.

ANSWER 5:

COMMAND STRUCTURE:

The UNIX system is command based, i.e., things happen because of the commands that you key in. The UNIX commands are seldom more than four characters long. All UNIX commands are single words like ls, cat, etc. These names are all in lowercase. Commands are case sensitive. Example- ls command will work correctly but LS will not work. The structure of command is as follows:

Command [option] [arguments]

In command used with multiple words, the first word is actually the command and the additional words are called arguments. A command often accepts several types of arguments and can be made to behave in numerous ways according to the argument provided. To enable the system to interpret commands and arguments as words, they have to be separated by spaces or tabs (can use any number of them). Option and arguments are not necessary with every command, some commands require them and some do not. The command with its arguments and options is known as command line. This line can be considered complete only after the user has hit [Enter]. The complete line is then fed to the shell as its input for interpretation and execution Options: It is a special argument preceded by a minus sign (-) to distinguish it from filenames. There must not be any whitespace between - and option (else many commands can lead to trouble!). Options are also arguments, but given a special name because their list is predetermined (arguments are not). Options can normally be combined with only one – sign, i.e., instead of using ls – l – a – t we might as well use ls – lat to obtain the same output. This facility reduces typing load, which becomes significant when using command with several options. The command breaks up the option combination into separate options. But there may be exceptions. Some commands won’t let us combine options in this way. Arguments: UNIX arguments range from simple to complex. They consist of options, expressions, instructions, filenames, etc. Many UNIX commands use a filename as argument so the command can take input from the file. If a command uses a filename as argument at all, it will generally be its last argument – and after all options. It’s also quite common to see many commands working with multiple filenames as argument: cp chap01 chap02 chap03 //cp copies files

4. ls – al List all the files and directories including hidden files with detailed information like permissions, owner, size, etc. in long format.

4. ls – A List all files including hidden files except for “.” and “..”- these refer to the entries for the current directory, and for the parent directory. 5. ls – – version Outputs version information and exit 6. ls – r Reverse the sorting sort and display the list of files

7. ls – i List the files along with their index number 8. ls – alt List all (including hidden files) directory contents, in long format, sorted by time 9. ls – l List the files in long format i.e. with details like an index number, owner name, group name, size, and permissions. 10. ls – o List the files in long format but without the group name

21. ls – Q List all files enclosed in double quotes. 22. ls – m Fill width with a comma separated list of files. 23. ls – n Like ls – l, but list numeric user and group IDs. 24. ls – lrt List all the files in the current directory in long format, sorted by modification time, oldest first. 25. ls – h

  • h option means human readable; with - l and - s, print sizes like 1K 234M 2G etc.

26. ls – lrS List all the files in the current directory in long format, sorted by size, smallest first 27. ls – g List the files in long format but without the owner name 28. ls – c List files sorted by creation time, newest first 29. ls – c

  • C option list entries by columns 31. ls --sort [WORD] Sorts by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X)

sort < name_list.txt Using this we can give the contents of the file as input to the sort command which will display the contents in sorted manner sort < name_list.txt >name_sort.txt Here we have first given the file name_list.txt to the sort command to sort the contents of the file and then the sorted output is directed to the name_sort.txt file

ANSWER 5:

INTRODUCTION AND OPTIONS OF CAT COMMAND:

cat(short for “concatenate”) command allows us to create single or multiple files, view contents of file, concatenate files and redirect output in terminals or file. General syntax: cat [OPTION] [FILE]...

  1. Display file contents cat [filename] When we use command with a file name then the command displays the contents of the file if the file exists. If the file does not exist then it shows an error message.
  2. New file creation or overwriting cat >[filename] This creates a file when it doesn’t exist instead of showing error and inputs the file content and if it exits then it overwrites the existing content with new inputted content
  3. New file creation or appending cat >>[filename] Same as previous, the only difference is that the entered content gets appended at the end of the file instead of getting overwritten.
  4. Display contents of multiple files cat [file1] ; cat [file2] or cat [file1] [file2] By this command both the files will be displayed one after the other.

ANSWER 6:

FEEDING THE OUTPUT OF ONE COMMAND TO ANOTHER BY PIPELINE

COMMAND:

ls |wc The output of ls command will be directed to the wc command which will count the number of lines, words and characters in the output of ls command and display it cat name_list.txt |head - 7 This will give the output of the cat command to the head command which has - 7 option with it. Thus the head command will extract first seven lines from the output of cat command and display it. cat name_list.txt |tail - 5 This will give the output of the cat command to the tail command which has - 5 option with it. Thus the tail command will extract last five lines from the output of cat command and display it cat name_list.txt | uniq |head - 7 |tail - 5 In this command line the execution is from left to right. So first the cat command will give the contents of the file which will be directed to the uniq command. The uniq command will then pick up the unique contents of the file and then this result is directed to head command. The head command has option - 7 with it so it will pick up the first seven lines of the result from the unique command. This is then directed to the tail command which has option - 5 and hence it picks up the last five lines from the output of head command cat name_list.txt |grep “shell” This will direct the output of the cat command to the grep command and the grep command will display all occurrence of “shell” in the output of cat command.

ANSWER 7:

WAYS FOR SIGNING OFF FROM LINUX:

1. exit Ends our session and close the terminal. This command always works. Alternatively, we can also use: **2. [ctrl-d]

  1. logout** But depending upon how environment has been set up, these two commands may or may not work. sudo shutdown The system will set a time for shutting down the system and shut down the system then unless the user cancels it by using – c option.