ACS Unix (Winter Term, ) Page 92

Similar documents
Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

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

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

File system Security (Access Rights)

Exploring UNIX: Session 5 (optional)

UNIX Tutorial Five

Oxford University Computing Services. Getting Started with Unix

Self-test Linux/UNIX fundamentals

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Files

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

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

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

Essential Linux Shell Commands

Unix Processes. What is a Process?

Introduction to UNIX Shell Exercises

UNIX Quick Reference

Removing files and directories, finding files and directories, controlling programs

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

UNIX File Hierarchy: Structure and Commands

Unix Workshop Aug 2014

Then, we modify the program list.1 to list two files.

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Getting started with Hugs on Linux

commandname flags arguments

MTU Computer Structure

INSE Lab 1 Introduction to UNIX Fall 2017

Getting started with Hugs on Linux

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.

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

UTA Tech Orientation Spring 2019

The Unix Shell. Job Control

Lab Assignment #1. University of Pittsburgh Department of Electrical and Computer Engineering

Computer Systems and Architecture

Part 1: Basic Commands/U3li3es

Unix Basics. Systems Programming Concepts

Introduction to Linux

unix intro Documentation

Working with Basic Linux. Daniel Balagué

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

CMU MSP 36602: Intro to UNIX and Scripting: Part 1

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

CS4350 Unix Programming. Outline

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

System Administration

Introduction to Linux Workshop 1

Unix Handouts. Shantanu N Kulkarni

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

CS197U: A Hands on Introduction to Unix

Introduction to Linux

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

Chap2: Operating-System Structures

-1- csh cd. cd alias!! ; set prompt=" pwd % " 16 cd. 17 cd.. 18 his /home% set prompt. alias. yasuoka : root :

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

UNIX Command Cheat Sheets

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

d. Permissions 600 on directory dir and 300 on file dir/foo. c. Permissions 700 on directory dir and 200 on file dir/foo.

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

UNIX Command Cheat Sheets

Introduction to Linux

UNIX Quick Reference

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

Linux System Administration

CS246 Spring14 Programming Paradigm Notes on Linux

Outline. Structure of a UNIX command

elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at

Introduction to Linux

Command-line interpreters

Introduction to LINUX. Bob Booth Mike Griffiths Deniz Savas March 2011 AP-LINUX3

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic

Course 144 Supplementary Materials. UNIX Fundamentals

CSC UNIX System, Spring 2015

Operating Systems. Copyleft 2005, Binnur Kurt

ACS Unix (Winter Term, ) Page 21

Find out where you currently are in the path Change directories to be at the root of your home directory (/home/username) cd ~

Perl and R Scripting for Biologists

CSCI 2132 Software Development. Lecture 4: Files and Directories

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

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

ORF 201 Computer Methods in Problem Solving. Lab 2: My House, My Home (Page)

Linux Command Line Interface. December 27, 2017

Exploring UNIX: Session 3

The Unix Shell & Shell Scripts

Introduction to Linux

Lab 2: Linux/Unix shell

CISC 220 fall 2011, set 1: Linux basics

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

IMPORTANT: Logging Off LOGGING IN

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

CSC209. Software Tools and Systems Programming.

Software I: Utilities and Internals. What is UNIX?

Practical 4. Linux Commands: Working with Directories

Transcription:

ACS-294-001 Unix (Winter Term, 2016-2017) Page 92 The Idea of a Link When Unix creates a file, it does two things: 1. Set space on a disk to store data in the file. 2. Create a structure called an inode (index node) to hold the basic information about the file. The inode contains all information that Unix needs to make use of the file. Unix keeps all the inodes in a large table. Within this table, each inode is known by a number called the inumber (index number). The directory does not really contain the file. All the directory contains is the name of the file and its inumber. Thus, the contents of a directory are actually quite small. The Contents of an Inode (Index Node) the name of the userid that owns the file the type of the file (ordinary, directory, special ) the size of the file where the data is stored file permissions the last time the file was modifies the last time the file was accessed the last time the inode was modified the number of links to the file When Unix needs to use the file, it looks up the name in the directory, uses the corresponding inumber to find the inode, and then uses the information in the inode to access the file. The connection between a file name and its inode is called a link. A link connects a file name with the file itself.

ACS-294-001 Unix (Winter Term, 2016-2017) Page 93 Multiple Links to the Same File Unix allows multiple links to the same file. In other words, the same file can be known by more than one name. The unique identifier of a file is its inumber, not its name. Creating a New Link: ln Example: To create a new link to an ordinary file, use the ln command with the following syntax: ln file newname where file is the name of an existing ordinary file, and newname is the name you want to give the link. ls -l total 4 -rw------- 1 sliao sliao 65 Jan 27 22:06 name ln name newfile ls -l total 8 -rw------- 2 sliao sliao 65 Jan 27 22:06 name -rw------- 2 sliao sliao 65 Jan 27 22:06 newfile

ACS-294-001 Unix (Winter Term, 2016-2017) Page 94 To make new links for one or more ordinary files and place them in a specified directory: Examples: ln file directory ls -l total 8 drwx------ 2 sliao sliao 4096 Jan 27 22:09 backups -rw------- 1 sliao sliao 65 Jan 27 22:09 file ls -l backups total 0 ln file backups ls -l total 8 drwx------ 2 sliao sliao 4096 Jan 27 22:10 backups -rw------- 2 sliao sliao 65 Jan 27 22:09 file ls -l backups total 4 -rw------- 2 sliao sliao 65 Jan 27 22:09 file rm file ls -l total 4 drwx------ 2 sliao sliao 4096 Jan 27 22:10 backups ls -l backups total 4 -rw------- 1 sliao sliao 65 Jan 27 22:09 file

ACS-294-001 Unix (Winter Term, 2016-2017) Page 95 How the Basic File Commands Work 1. COPY: cp Unix creates a new file with its own inumber. You end up with two files. 2. RENAME or MOVE: mv Unix changes the file name, but keeps the same inumber. You end up with one file. 3. CREATE A LINK: ln Unix makes a new directory entry using the file name you specify. You end up with one file and two names. 4. REMOVE: rm Examples: Unix deletes the link between the file name and the inumber by removing the directory entry. The file will not be deleted until the last link is removed. ls -l total 4 -rw------- 1 sliao sliao 65 Jan 27 22:09 file ln file file1 ls -l total 8 -rw------- 2 sliao sliao 65 Jan 27 22:09 file -rw------- 2 sliao sliao 65 Jan 27 22:09 file1 ln file file2 ls -l total 12 -rw------- 3 sliao sliao 65 Jan 27 22:09 file -rw------- 3 sliao sliao 65 Jan 27 22:09 file1 -rw------- 3 sliao sliao 65 Jan 27 22:09 file2 rm file file1 ls -l total 4 -rw------- 1 sliao sliao 65 Jan 27 22:09 file2

ACS-294-001 Unix (Winter Term, 2016-2017) Page 96 Symbolic Links: ln -s There are two limitations about the links we discussed above: 1. You cannot create a link to a directory. 2. You cannot create a link to a file in a different file system. The solution is to use ln with the -s option. Such a link, which is called symbolic link, does not contain the inumber of the original file. Rather, it contains the pathname of the original file. Example: % ls -l total 7 -rw-r--r-- 1 s_liao wheel 1411 Jan 11 10:20 index.html -rw------- 1 s_liao wheel 496 Jan 20 18:50 mbox drwxr-xr-x 2 s_liao wheel 512 Feb 17 17:06 misc drwxr-xr-x 7 s_liao wheel 2560 Feb 15 00:07 public_html % cd public_html/courses/2941 % pwd /usr/home/s_liao/public_html/courses/2941 % cd % ln -s public_html/courses/2941 % ls -l total 7 lrwxr-xr-x 1 s_liao wheel 24 Feb 17 17:07 2941 -> public_html/courses/2941 -rw-r--r-- 1 s_liao wheel 1411 Jan 11 10:20 index.html -rw------- 1 s_liao wheel 496 Jan 20 18:50 mbox drwxr-xr-x 2 s_liao wheel 512 Feb 17 17:06 misc drwxr-xr-x 7 s_liao wheel 2560 Feb 15 00:07 public_html % cd 2941 % pwd /usr/home/s_liao/public_html/courses/2941 %

ACS-294-001 Unix (Winter Term, 2016-2017) Page 97 Processes and Job Control A process is a program that is executing. Every time you enter a command that executes a program, Unix creates a new process. Displaying the Status of Your Processes: ps Without options, ps (process status) will only display the process ID, terminal identifier, cumulative execution time, and the command name. The ps command has a large number of options that vary from system to system. By using these options, you can display a great deal of technical information about each process. Examples: ps 1422 pts/2 00:00:00 csh 1430 pts/2 00:00:00 ps w grep sliao sliao pts/2 s01060014d1c82ea 10:13 2.00s 0.00s 0.00s w sliao pts/3 s01060014d1c82ea 10:14 13.00s 0.00s 0.00s -csh ps -u sliao 1421? 00:00:00 sshd 1422 pts/2 00:00:00 csh 1427 pts/3 00:00:00 csh 1433 pts/2 00:00:00 ps Foreground and Background Processes When you enter a command to run a program, the shell normally waits for the program to finish before asking you to enter another command. In this case, we say the process is running in the foreground.

ACS-294-001 Unix (Winter Term, 2016-2017) Page 98 However, it is possible to start a program, and then move right along to the next command. This is called that running a program in the background. To start a program running in the background, all you need to do is to type an & character at the end of the command. Example: ps -u sliao 1421? 00:00:00 sshd 1422 pts/2 00:00:00 csh 1548 pts/2 00:00:00 ps circle& [1] 1549 ps -u sliao 1421? 00:00:00 sshd 1422 pts/2 00:00:00 csh 1549 pts/2 00:00:03 circle 1550 pts/2 00:00:00 ps [1] Done circle ps -u sliao 1421? 00:00:00 sshd 1422 pts/2 00:00:00 csh 1653 pts/2 00:00:00 ps The state of the process: PID TTY STIME TIME The process ID The controlling terminal for the process The starting time of the process The cumulative execution time for the process

ACS-294-001 Unix (Winter Term, 2016-2017) Page 99 Suspending a Process: Job Control If you are working with a program and you want to pause it temporarily, you can suspend the process by pressing ^Z. Then, you can enter any command. When a process is suspended, it waits indefinitely. To restart it, you can use either the fg (foreground) or bg (background) commands. This capability being able to suspend and restart processes is called Job Control. Displaying a List of Suspended Jobs: jobs Example: To keep track of your suspended jobs, you can use the jobs command. The syntax is: jobs [-l] -l displays the job number and process ID jobs circle ^Z Stopped jobs [1] + Stopped circle jobs -l [1] + 1934 Stopped circle Moving a Suspended Job to the Foreground: fg When you restart a suspended job, you can use the fg command to move the job to the foreground. The syntax is: fg [%job...]

ACS-294-001 Unix (Winter Term, 2016-2017) Page 100 where job is the name or number of a suspended job. If you enter the command by itself, the shell will restart the current job, which is the most recently suspended job. If you want to move a different program to the foreground, you can specify the one you want. Specification Meaning %nn job number nn % the current job %+ same as % %- the previous job Examples: jobs [1] + Stopped circle [2] - Running square fg circle ^Z Stopped fg %- square ^Z Stopped fg %1 circle ^Z Stopped jobs [1] + Stopped circle [2] - Stopped square fg % circle ^Z Stopped

ACS-294-001 Unix (Winter Term, 2016-2017) Page 101 Moving a Suspended Job to the Background: bg To move a suspended job to the background, you can use the bg command. The syntax is: bg [%job] where job is the name or number of a suspended job. Suspending a Background Process: stop To suspend a job that is running in background, use the stop command: stop %job where job is the name or number of the running process. Examples: jobs [1] + Stopped circle [2] - Stopped square bg %1 [1] circle & jobs [1] Running circle [2] + Stopped square stop %1 [1] + Stopped (signal) circle jobs [1] + Stopped (signal) circle [2] - Stopped square

ACS-294-001 Unix (Winter Term, 2016-2017) Page 102 Killing a Process: kill When you are using a regular program running in the foreground, you can terminate it by pressing the intr key (^C key for most of systems). How can you terminate a program that is running in the background? You can do this by using the kill command. The syntax is: kill [-signal] pid where signal is the type of signal you want to send, and pid identifies the process that you want to terminate. In fact, the kill command is designed to send a signal to a process (or processes) specified by each pid. Each signal has its own name and identification number. Although most of systems have many different signals, only two of them are of interest to regular users. Signal number 15 is called TERM (terminate) which has the effect of killing the process (and this is why the command is called kill). Most of the time, a process will recognize the TERM signal and shut itself down. However, a program could have been designed to ignore this signal (or something may go wrong). Signal number 9 is called KILL, which is a stronger form of TERM. Unlike TERM, the KILL signal, by definition, cannot be ignored. Using KILL ensures a sure kill.

ACS-294-001 Unix (Winter Term, 2016-2017) Page 103 Examples: ps 32149 pts/3 00:00:00 csh 32312 pts/3 00:01:09 square 32586 pts/3 00:00:05 circle 32591 pts/3 00:00:00 ps kill 32312 [2] Terminated square ps 32149 pts/3 00:00:00 csh 32586 pts/3 00:00:25 circle 32598 pts/3 00:00:00 ps circle ^Z Stopped jobs [3] - Running circle [4] + Stopped circle kill -9 %4 [4] Killed circle ps 32149 pts/3 00:00:00 csh 32586 pts/3 00:01:57 circle 32628 pts/3 00:00:00 ps