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

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

More Scripting Todd Kelley CST8207 Todd Kelley 1

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal

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

Processes. System tasks Campus-Booster ID : **XXXXX. Copyright SUPINFO. All rights reserved

Most of the work is done in the context of the process rather than handled separately by the kernel

Bamuengine.com. Chapter 7. The Process

07 - Processes and Jobs

Managing Processes Process: A running program

Chapter 9: Process management. Chapter 9 Process management

Linux System Administration

System Administration

Process States. Controlling processes. Process states. PID and PPID UID and EUID GID and EGID Niceness Control terminal. Runnable. Sleeping.

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

APPLIED INFORMATICS Processes. Bash characteristics. Command type. Aliases.

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Lecture 5: Jobs and Processes

bash, part 3 Chris GauthierDickey

Command-line interpreters

CS Unix Tools. Fall 2010 Lecture 10. Hussam Abu-Libdeh based on slides by David Slater. September 29th, 2010

Unix Processes. What is a Process?

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

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

Ch 9: Periodic Processes

Chapter 4 Controlling Processes

Review of Fundamentals

PROCESSES. At least they re not ISO-9001 processes

Unix Scripts and Job Scheduling. Overview. Running a Shell Script

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

Q) Q) What is Linux and why is it so popular? Answer - Linux is an operating system that uses UNIX like Operating system...

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2018

The Unix Shell & Shell Scripts

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Lab 2: Linux/Unix shell

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

(MCQZ-CS604 Operating Systems)

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

Manage Jobs with cron and at

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

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

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

Assignment 1. Teaching Assistant: Michalis Pachilakis (

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

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Shells and Processes. Bryce Boe 2012/08/08 CS32, Summer 2012 B

Linux 系统介绍 (III) 袁华

Linux shell scripting Getting started *

COSC243 Part 2: Operating Systems

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Workshop on Inter Process Communication Solutions

HW 1: Shell. Contents CS 162. Due: September 18, Getting started 2. 2 Add support for cd and pwd 2. 3 Program execution 2. 4 Path resolution 3

NAME top display top CPU processes. SYNOPSIS top [ ] [d delay] [p pid] [q] [c] [C] [S] [s] [i] [n iter] [b]

5/8/2012. Controlling User Processes Chapter 10

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Signals: Management and Implementation. Sanjiv K. Bhatia Univ. of Missouri St. Louis

Sperimentazioni I LINUX commands tutorial - Part II

Processes. CS439: Principles of Computer Systems January 24, 2018

ACS Unix (Winter Term, ) Page 92

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy

Study Guide Processes & Job Control

Processes. CS439: Principles of Computer Systems January 30, 2019

Useful Unix Commands Cheat Sheet

Shells and Shell Programming

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

Getting your department account

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

CS370 Operating Systems

Shells and Shell Programming

So far, we know how to create processes. How do we communicate with them? Primary mechanism: signals

Processes and Shells

G54ADM Sample Exam Questions and Answers

Simplest version of DayOfYear

Advanced Unix Concepts. Satyajit Rai

Systems Programming/ C and UNIX

Introduction to Linux and Supercomputers

Introduction to UNIX Shell Exercises

User Commands ps ( 1 )

ECE 650 Systems Programming & Engineering. Spring 2018

Exploring UNIX: Session 5 (optional)

KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 6

Process Control. Philipp Koehn. 23 April 2018

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

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

CST Algonquin College 2

CS 307: UNIX PROGRAMMING ENVIRONMENT REVIEW FOR EXAM 2

CSCI0330 Intro Computer Systems Doeppner. Project Shell 2. Due: November 8, 2017 at 11:59pm. 1 Introduction 2

SUDO(8) System Manager s Manual SUDO(8)

Linux Command Line Primer. By: Scott Marshall

CS631 - Advanced Programming in the UNIX Environment. Process Groups, Sessions, Signals

Processes. Dr. Yingwu Zhu

minit Felix von Leitner September 2004 minit

Each terminal window has a process group associated with it this defines the current foreground process group. Keyboard-generated signals are sent to

UNIX Quick Reference

Introduction to Linux

Advanced Unix/Linux System Program. Instructor: William W.Y. Hsu

Assignment clarifications

System Programming. Introduction to Unix

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

SOFTWARE ARCHITECTURE 3. SHELL

Transcription:

Processes 1

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

elinks is a text-based (character mode) web browser we will use it to enable our scripts to retrieve web pages in assignment 6, we use it to retrieve a weather webpage elinks -dump -no-numbering -no-references <URL> Example elinks -dump -no-numbering -no-references \ 'http://weather.gc.ca/rss/city/on-118_e.xml' Could grep this to extract information (maybe with A option) 3

use the mail command to send outgoing and read incoming email on the CLS Sending outgoing email (bold font shows what the user types) $ mail username@example.com Cc: Subject: First Message from CLS This is a test message. ^D $ 4

text mode mail reader incoming email is stored in /var/spool/mail/<username> use the mail command to read it you'll see a list of messages, each preceded by a number (the header list) enter a number to see that message enter h to see the header list again when you enter q, mail will quit and messages you read will be stored in ~/mbox mail f to see the messages in ~/mbox 5

Any program we run executes as a process Processes have the following attributes a process id: PID a parent process id: PPID a nice number (related to priority) controlling terminal Real (RUID) and effective (EUID) user id Real (RGID) and effective (EGID) group id Also: a current working directory a umask value an environment (values of environment variables) 6

We have already been using the ps command to print out information about processes running on the system ps ef or ps aux piped to grep is common there are many options for printing specific info in a specific way: man ps or ps -h ps l # long format ps f versus ps fw 7

top displays some system information, and a list of processes, ordered on a column the most important keys are?, h, and q (according to man page) load average: 5min, 10min, 15min load average is number of processes running or in uninterruptable state (disk IO, others) no exact rule, but if load average is more than 1-1.5 times the number of CPUs, the machine is overloaded in some way and you have a problem (your mileage may vary) 8

pstree: connects parents and children in a pictorial display free: memory usage vmstat: processes, memory, and more 9

Runnable: ready to go Sleeping: choosing not to go Stopped: suspended indefinitely, as in ^Z Uninterruptable Sleep: waiting on a disk I/O operation, or similar Zombie or Defunct: process has completed, but it's still in the process table waiting for parent to take action 10

Each process has a priority, which you can control with the nice command -20 highest priority, 19 lowest priority nice [ n increment] command nice n 10 long_command # 10 is default only superuser can specify negative increments For processes already running: renice priority p PID or renice n priority p PID 11

your shell can run several processes for you at once we can run commands in the background command & we can put a running command in the background ^Z what jobs are there? jobs resume a stopped job bg %N fg %N # background, where N is a job number # foreground 12

When we type ^C when a process is running in the foreground, the process receives a SIGINT signal, which by default would cause a process to terminate. SIGINT: ^C (default), similar to SIGTERM SIGHUP: terminal has been closed SIGTERM: clean up if necessary, then die SIGKILL: die right now We can send these signals to a process with the kill command 13

kill SIGNAL PID #send SIGNAL to process PID When system shuts down, it sends all processes a SIGTERM waits a few seconds (5 or 10) sends all processes a SIGKILL Why not just wait for the SIGTERM to finish? Because SIGTERM can be handled, possibly ignored, it's optional SIGKILL cannot be handled it works unless the process is in an uninterruptible state (maybe disk I/O, NFS) 14

If kill -9 PID (kill SIGKILL PID) as root doesn't kill the process, it is in an uninterruptible state if uninterruptible processes don't become interruptible, there may be a system problem (bad disk, misconfigured NFS filesystem, etc) Reboot may be the only way to get rid of them 15

summary of all the POSIX signals: http://en.wikipedia.org/wiki/unix_signal 16

Signals and the TRAP statement Various signals can be trapped and your own script code executed instead of the system's normal code. Although there are up to 64 signals available, we will consider only a few of them: SIGHUP (signal 1 or HUP: hang up) is issued for a remote connection when the connection is lost or terminated; it's also used to tap a daemon on the shoulder, to re-read its config files. SIGINT (signal 2 or INT) is the keyboard interrupt signal given by Control-C. SIGKILL (signal 9 or KILL) cannot be ignored or trapped. SIGTERM (signal 15 or TERM) is the default signal used by kill(1) and killall(1). 17

Signal-like events and TRAP The EXIT event (also "signal" 0) occurs upon exit from the current shell. The DEBUG event takes place before every simple command, for command, case command, select command, and before the first command in a function. See also the description of extdebug for the shopt built-in for details of its effect. The ERR event takes place for each simple command with a non-zero exit status, subject to these conditions: it is not executed if the failed command is part of a while, until, or if condition expression, or in a && or list, or if the command s return value is being inverted via!. See also errexit for details. The RETURN event occurs each time a shell function or a script executed with the. (that's a dot) or source builtin returns to its caller. 18

Signals and the TRAP statement You can set a trap: trap 'statement; statement; ' event-list The trap statement list is read by the shell twice, first when it's set (it's set once only, before it is to be used, and stays active until you clear it). It's read a second time when it's executed. If you enclose the statement in single quotes, substitutions only take place at execution time. If you use double quotes, substitutions will take place upon both readings. If statement is omitted, the signals (use - (dash)) for all) are reset to the default. If statement is a null (empty) string, the signals specified will be ignored. 19

Signals and the TRAP statement To set a trap for SIGINT: trap 'statement; statement; ' INT To turn it off again: trap INT To prevent any SIGINT handling (ignore signals): trap " " INT Be cautious in trapping SIGINT: how will you stop a runaway script? To see what traps are set (you can see traps for specific events by listing the names or numbers): trap -p To list the names for signals 1 to SIGRTMAX: trap -l # that's an ell, not a one 20

#!/bin/sh -u count=0 Trap Sample Script # set trap to echo, then turn itself off trap 'echo -e \\nsigint ignored in $count; ' SIGINT # loop for a while while (( count < 10 )); do (( count++ )) read -p "$count loop again? " response done # if loop ends, display count echo loop count $count exit 0 21

System Prompt$./traptest 1 loop again? 2 loop again? 3 loop again? 4 loop again? y 5 loop again? n 6 loop again? 7 loop again? q 8 loop again? help 9 loop again? ^C SIGINT ignored in 9 10 loop again? q 11 loop again? y 12 loop again? n 13 loop again? ^C System Prompt$ 22

To run a command regularly and automatically, we use the cron facility The cron daemon process every minute checks to see if commands specified in crontab files need to be run for now, we're concerned only with our user crontab files, which are /var/spool/cron/* for example, /var/spool/cron/user1 is user1's crontab file 23

full details from man 5 crontab recall that is how we read section 5 of the manual (section 5 of the manual is file formats) man crontab will give info about the crontab command (in default section 1 of the manual) create a file containing your cron instructions (see next slide), naming that file, say, myuser.crontab run the crontab command to submit that file's contents to be your user's crontab file: crontab < myuser.crontab alternatively, you can edit your user's live crontab file: crontab -e 24

crontab format (man 5 crontab) All fields must contain a value of some valid kind Field are separated by one or more spaces Asterisk (*) indicates the entire range #.---------------- minute (0-59) #.------------- hour (0-23) #.--------- day of month (1-31) #.------ month (1-12) #.--- day of week (0 7, both 0 and 7 are Sunday) # 0 6 1 * * /home/user/bin/mycommand 1 6 15 * * /home/user/bin/anothercommand > /dev/null 2>&1 25

ranges with dash are allowed: first-last * means every value first-last lists are allowed: first,second,third steps indicated with '/' are allowed after ranges or asterisk: */2 means every second one 1-7/2 means 1,3,5,7 26

crontab l list the contents of your current live crontab file crontab e edit the contents of your current live crontab file crontab read the new contents of for your crontab file from stdin crontab r remove your current crontab file 27

see man 5 crontab for example crontab really, see the example: man 5 crontab things to watch out for input for your commands (they run without anyone to type input) output of commands (if you don't (re)direct output, the output will be emailed better if you handle it) error output of commands (same as for output above) summary: it's best if your commands in a crontab are arranged with input and output already handled, not relying on output to be emailed by cron if you want to email, do it explicitly in your command somehow, and test that command before putting it into your crontab 28

at command runs a set of commands at a later time at command takes a TIME parameter and reads the set of commands from standard input example (run commands at 4pm 3 days from now) at 4pm + 3 days rm f /home/usr/foo touch /home/usr/newfoo ^D other at-related commands: atrm, atq for details: man at as with cron, you must be aware of how your commands will get their input (if any) and what will happen to their output (if any) 29