

















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 57
This page cannot be seen from the preview
Don't miss anything!
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:
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:
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.
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.
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:
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.
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:
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
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
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
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]...
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.
1. exit Ends our session and close the terminal. This command always works. Alternatively, we can also use: **2. [ctrl-d]