PESIT Bangalore South Campus

Similar documents
Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

PESIT Bangalore South Campus

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Files (review) and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

5/8/2012. Creating and Changing Directories Chapter 7

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

St. MARTIN S ENGINEERING COLLEGE Dhulapally,Secunderabad DEPARTMENT OF INFORMATION TECHNOLOGY Academic year

Unix Processes. What is a Process?

Chapter 1 - Introduction. September 8, 2016

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

Systems Programming/ C and UNIX

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

Welcome to Linux. Lecture 1.1

bash startup files Linux/Unix files stty Todd Kelley CST8207 Todd Kelley 1

CS/CIS 249 SP18 - Intro to Information Security

CST Lab 2 Review #1

CSC209S Midterm (L0101) Spring 1999 University of Toronto Department of Computer Science

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

UNIX File Hierarchy: Structure and Commands

ADVANCED OPERATING SYSTEMS

Bamuengine.com. Chapter 7. The Process

Unix Introduction to UNIX

ITST Searching, Extracting & Archiving Data

(32 KB) 216 * 215 = 231 = 2GB

UNIT I Linux Utilities

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

lsx [ls_options ] [names]

CST Algonquin College 2

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Processes. CS3026 Operating Systems Lecture 05

FILESYSTEMS. Mmmm crunchy

LAB 8 (Aug 4/5) Unix Utilities

CSE/ISE 311: Systems Administra5on Access Control and Processes

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

UNIT I Linux Utilities and Working with Bash

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

A Brief Introduction to the Linux Shell for Data Science

Linux System Administration

An Introduction to Unix Power Tools

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Module 8 Pipes, Redirection and REGEX

Introduction to Computer Security

File system links. Week Overview. Hard and symbolic links Process management

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

LAB 8 (Aug 4/5) Unix Utilities

Project 5 File System Protection

Practical 4. Linux Commands: Working with Directories

Files and Directories

Computer Programming Lecture 1 이윤진서울대학교

UNIX files searching, and other interrogation techniques

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Network Lab # 7 Permissions

Basic Linux (Bash) Commands

Building blocks for Unix power tools

Working with Basic Linux. Daniel Balagué

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

Project 5 File System Protection

I/O and Shell Scripting

Linux & Shell Programming 2014

ADVANCED LINUX SYSTEM ADMINISTRATION

Review of Fundamentals

Project 1: Implementing a Shell

File Systems. What do we need to know?

Operating Systems Lab

Introduction to Linux

RH033 Red Hat Linux Essentials

This document gives a general overview of the work done by an operating system and gives specific examples from UNIX.

Filesystem Hierarchy and Permissions

CS 326: Operating Systems. Process Execution. Lecture 5

2) clear :- It clears the terminal screen. Syntax :- clear

Course 144 Supplementary Materials. UNIX Fundamentals

Overview. Over the next four weeks, we will look at these topics: Building Blocks. Advanced Authentication Issues.

File I/O and File Systems

Please choose the best answer. More than one answer might be true, but choose the one that is best.

Data Security and Privacy. Unix Discretionary Access Control

SE350: Operating Systems

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

Basic OS Progamming Abstrac7ons

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

Basic OS Progamming Abstrac2ons

Universidad Carlos III de Madrid Computer Science and Engineering Department Operating Systems Course

File permission u owner of file/directory (user) g group of the file/directory o other a all

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

Working with Unix Processes. Copyright 2012 Jesse Storimer. All rights reserved. This ebook is licensed for individual use only.

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Implementation of a simple shell, xssh

Programming Assignment #1: A Simple Shell

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Operating Systems Lab 1 (Users, Groups, and Security)

Basic File Attributes

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 18: Naming, Directories, and File Caching

Transcription:

INTERNAL ASSESSMENT TEST - 2 Date : 20/09/2016 Max Marks : 0 Subject & Code : Unix Shell Programming (15CS36) Section : 3 rd Sem ISE/CSE Name of faculty : Prof Ajoy Time : 11:30am to 1:00pm SOLUTIONS 1 a Explain the significance of these two special files /dev/null and /dev/tty. Answers:- /dev/null: if we want to execute a command but don t like to see its contents on the screen, we may wish to redirect the output to a file called /dev/null. It is a special file that can accept any stream without growing in size. It s size is always zero. /dev/tty: this file indicates one s terminal. In a shell script, if we wish to redirect the output of some select statements explicitly to the terminal. In such cases you can redirect these explicitly to /dev/tty inside the script. b Explain the usage of wild card characters in - i) [A Z]????* iii) *[0 9]* ii) *[!0 9] iv) *[!s] [!h] Answers : - i) Refers to all the files or names starting with any alphabet from A to Z (in uppercase) followed by characters and further followed by any number of characters in any form (numbers, characters, special characters etc) ii) iii) iv) It refers to all the files or names starting with any character and containing any number of characters but should not end with a number i.e anything from 0 to 9 should not be there at end. It refers to all the files or names that can contain any character, any number of times in the beginning as well as in the end but should contain one number between 0 to 9 in the name. It refers to all the files or names that can be beginning with any character and can contain any number of characters but should not contain s as second last character and h as last character. 2 What is a process? Mention briefly the role of fork - exec mechanism in process creation. Answers:- A process is a program in execution. A process is said to be born when the program starts ececution 8

and remains alive as long as the program is active. After execution is complete, the process is said to die. The kernel is responsible for the management of the process. Two important attributes of process are:- a) The process-id (PID) : each process is uniquely identified by a unique integer called the PID, that is allocated by the kernel when the process is born. The PID can be used to control a process. b) The parent PID (PPID) : the PID of the parent is available as a process attributes. There are three types of process :- a) Interactive b) Batch c) Daemon There are three distint phase in the creation of a process and uses three important system calls i.e. fork, exec, and wait. The three phases are discussed below: a) Fork: a process in unix is created with the fork system call which creates a copy of the process that creates it. The process image is identical to that of the calling process, except for a few parameters like the PID. The child gets a new PID. b) Exec: the forked child overwrites its own image with the code and data of the new program. This mechanism is called exec, and the child process is said to exec a new program, using one of the family of exec system calls. The PID and PPID of the exec d process remains unchanged. c) Wait: the parent then executes the wait system call to wait for the child to complete. It picks up the exit status of the child and continues with its other functions. A parent need not to decide to wait for the child to terminate. The important attributes that are inherited from parent process to child process are ;- The real UID and real GID of the process The effective UID and GID of the process 3 What are file attributes? Explain how to change basic file permissions, with an example. Answers: - File attributes are the features of file which on combination help us uniquely identify a file. Every file is associated with a table that contains all that we could possibly need to know about a file except its name and contents. This table is called the inode and is accessed by the inode number. The inode contains Unix the following attributes :- a) File type b) Permissions c) Links d) User e) Group f) File Size in bytes g) Last modified h) Date and time of last accessed i) An array of pointers that keep track of all disk blocks used by the file Most file systems have methods to assign permissions or access rights to specific users and groups of users. These systems control the ability of the users to view, change, navigate, and execute the contents 8

of the file system. Permissions on Unix-like systems are managed in three distinct scopes or classes. These scopes are known as user, group, and others. Files and directories are owned by a user. The owner determines the file's user class. Distinct permissions apply to the owner. Files and directories are assigned a group, which define the file's group class. Distinct permissions apply to members of the file's group. The owner may be a member of the file's group. Users who are not the owner, nor a member of the group, comprise a file's others class. Distinct permissions apply to others. Permissions :- Unix-like systems implement three specific permissions that apply to each class: The read permission grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory, but not to find out any further information about them such as contents, file type, size, ownership, permissions. The write permission grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files. The execute permission grants the ability to execute a file. This permission must be set for executable programs, including shell scripts, in order to allow the operating system to run them. When set for a directory, this permission grants the ability to access file contents and metainformation if its name is known, but not list files inside the directory, unless read is set also. Each of the three characters represent the read, write, and execute permissions: r if reading is permitted, - if it is not. w if writing is permitted, - if it is not. x if execution is permitted, - if it is not. In some permission systems additional symbols in the ls -l display represent additional permission features. Another method for representing Unix permissions is an octal (base-8) notation as shown by stat -c %a. This notation consists of at least three digits. Each of the three rightmost digits represents a different component of the permissions: owner, group, and others. Each of these digits is the sum of its component bits in the binary numeral system. As a result, specific bits add to the sum as it is represented by a numeral: The read bit adds to its total (in binary 100), The write bit adds 2 to its total (in binary 010), and The execute bit adds 1 to its total (in binary 001). Changing File Permissions

To change the file permission on any of the files you own, you can use the chmod command. The command syntax consists of the group/person to which permission is being granted or revoked, and the type of permission being granted or revoked. The letter u is for the owner, g for the group, and o for others (public). It can be done in two ways: relative and absolute To change permission on a file or directory, specify the the group, then + or - to indicate whether the permission is to be granted or revoked, then the access type. For example, to grant your group read permission to the files directory, you could enter chmod g+r files. Or, to remove public executable access to script, you could enter chmod o-x script a What are hard links and soft links? Explain with examples. Answers: - Hard links: indistinguishable from other directory entries, because every directory entry is hard link "original" can be moved or deleted without breaking other hard links to the same inode only possible within the same filesystem permissions must be the same as those on the "original" (permissions are stored in the inode, not the directory entry) ln command is used for making hard links to a file files have the same inode number in hard link can only be made to files, not directories Symbolic links (soft links) simply records that point to another file path. (ls -l will show what path a same link points to) will break if original is moved or deleted. (In some cases it is actually desirable for a link to point to whatever file currently occupies a particular location) can point to a file in a different file system ln s command is used to create soft links to files. can point to a directory on some file system formats, it is possible for the same link to have different permissions than the file it points to (this is uncommon) b Write a short note on find command Answers :- Find is one of the powerful utility of Unix (or Linux) used for searching the files in a directory

hierarchy. The syntax of find command is find [pathnames] [conditions][action] By using conditions like name, -perm, -size etc, we can make searches according to name, permissions, size etc. Path name is provided to search the file in that specified path. Action determines what to do with the found files like to print them as output etc. example:- $ find perm 777 print This example will find all files in the current directory with rw*rw*rw permissions and print those files as output.

5 What is grep. Give some options used by grep? Locate lines longer than 100 and smaller than 150 characters using grep. Answers: - Grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines. The options used by grep command is :- -r reversing the searching criteria -n it gives no of lines -i (ignore-case)ignore case distinctions in both the PATTERN and the input files. -c Suppress normal output; instead print a count of matching lines for each input file. With the -v, -- invert-match option There are many more options used by grep command. Example: - $ grep manager emp.lst (searches for manager in the file and outputs the corresponding lines) $grep ^[A-Z] emp.lst (outputs line beginning with capital letters) 8 Grep command for locating lines longer than 100 and smaller than 150 is: - grep -E '^.{101,19}$' infile or, grep x.\{100,150\} -E this is the same as sed's -r option but for grep command. So if you don't want to use is just escape the curly braces.