Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 191 - Lesson 12 System Monitoring 1. CIS 191 - Lesson 12 ps command 2.

Similar presentations


Presentation on theme: "CIS 191 - Lesson 12 System Monitoring 1. CIS 191 - Lesson 12 ps command 2."— Presentation transcript:

1 CIS Lesson 12 System Monitoring 1

2 CIS Lesson 12 ps command 2

3 CIS Lesson 12 Process Information InformationDescription PIDProcess Identification Number, a unique number identifying the process PPIDParent PID, the PID of the parent process (like … in the file hierarchy) UIDThe user running the process TTYThe terminal that the process's stdin and stdout are connected to SThe status of the process: S=Sleeping, R=Running, T=Stopped, Z=Zombie PRIProcess priority SZProcess size CMDThe name of the process (the command being run) CThe CPU utilization of the process WCHANWaiting channel (name of kernel function in which the process is sleeping) FFlags (1=forked but didn't exit, 4=used superuser privileges) TIMECumulative CPU time NINice value Just a few of types of information kept on a process. Use man ps to see a lot more. 3

4 CIS Lesson 12 Process Information Show just my processes Show all processes with a tty 4

5 CIS Lesson 12 Process Information -a show processes with a terminal x option shows full commands being run and states (most are asleep). I'm using two Putty sessions, in one session I have the man page open for ps, the other I'm issuing ps commands 5

6 CIS Lesson 12 Process Information Use the u option to look at processes owned by a specific user 6

7 CIS Lesson 12 Process Information Use the u option to look at processes owned by a specific user 7

8 CIS Lesson 12 Process Information Use –l for additional options 8

9 CIS Lesson 12 Process Information 9

10 CIS Lesson 12 Process Information root Sep10 ? 00:00:00 [ata/1] root Sep10 ? 00:00:00 [ata_aux] root Sep10 ? 00:00:00 [scsi_eh_0] root Sep10 ? 00:00:00 [scsi_eh_1] root Sep10 ? 00:01:25 [kjournald] root Sep10 ? 00:00:00 [kauditd] root Sep10 ? 00:00:00 /sbin/udevd -d root Sep10 ? 00:00:01 [kedac] root Sep10 ? 00:00:00 [kmpathd/0] root Sep10 ? 00:00:00 [kmpathd/1] root Sep10 ? 00:00:05 /usr/sbin/restorecond root Sep10 ? 00:00:11 auditd root Sep10 ? 00:00:05 /sbin/audispd root Sep10 ? 00:00:23 syslogd -m 0 root Sep10 ? 00:00:00 klogd -x root Sep10 ? 00:00:20 mcstransd rpc Sep10 ? 00:00:00 portmap root Sep10 ? 00:01:18 /usr/bin/python -E /usr/sbin/setroub rpcuser Sep10 ? 00:00:00 rpc.statd root Sep10 ? 00:00:00 rpc.idmapd root Sep10 ? 00:00:00 /usr/bin/vmnet-bridge -d /var/run/vm root Sep10 ? 00:00:00 /usr/bin/vmnet-natd -d /var/run/vmne dbus Sep10 ? 00:00:15 dbus-daemon --system root Sep10 ? 00:00:51 pcscd root Sep10 ? 00:00:00 /usr/bin/hidd --server root Sep10 ? 00:00:02 automount 10

11 CIS Lesson 12 Process Information root Sep10 ? 00:00:00./hpiod root Sep10 ? 00:00:00 python./hpssd.py root Sep10 ? 00:00:00 cupsd root Sep10 ? 00:00:11 /usr/sbin/sshd root Sep10 ? 00:00:01 sendmail: accepting connections smmsp Sep10 ? 00:00:00 sendmail: Queue for root Sep10 ? 00:00:00 crond xfs Sep10 ? 00:00:00 xfs -droppriv -daemon root Sep10 ? 00:00:00 /usr/sbin/atd root Sep10 ? 00:00:00 rhnsd --interval 240 root Sep10 ? 00:01:33 /usr/bin/python -tt /usr/sbin/yum-up root Sep10 ? 00:00:00 /usr/libexec/gam_server root Sep10 ? 00:00:00 /usr/bin/vmnet-netifup -d /var/run/v root Sep10 ? 00:00:00 /usr/bin/vmnet-netifup -d /var/run/v root Sep10 ? 00:00:00 /usr/bin/vmnet-netifup -d /var/run/v root Sep10 ? 00:00:00 /usr/bin/vmnet-dhcpd -cf /etc/vmware root Sep10 ? 00:00:00 /usr/bin/vmnet-dhcpd -cf /etc/vmware root Sep10 ? 00:00:00 /usr/bin/vmnet-dhcpd -cf /etc/vmware Sep10 ? 00:00:01 hald root Sep10 ? 00:00:00 hald-runner Sep10 ? 00:00:00 hald-addon-acpi: listening on acpid Sep10 ? 00:00:00 hald-addon-keyboard: listening on /d Sep10 ? 00:00:00 hald-addon-keyboard: listening on /d root Sep10 ? 00:02:46 hald-addon-storage: polling /dev/hda root Sep10 ? 00:00:00 /usr/sbin/smartd -q never root Sep10 tty2 00:00:00 /sbin/mingetty tty2 11

12 CIS Lesson 12 Process Information root Sep10 tty3 00:00:00 /sbin/mingetty tty3 root :19 ? 00:00:00 sshd: rsimms [priv] rsimms :19 ? 00:00:00 sshd: rsimms :19 pts/0 00:00:00 -bash root :14 ? 00:00:00 sshd: valdemar [priv] valdemar :14 ? 00:00:00 sshd: valdemar :14 pts/5 00:00:00 -bash rsimms :36 pts/0 00:00:00 man ps rsimms :36 pts/0 00:00:00 sh -c (cd /usr/share/man && (echo ". rsimms :36 pts/0 00:00:00 sh -c (cd /usr/share/man && (echo ". rsimms :36 pts/0 00:00:00 /usr/bin/less -is root :37 ? 00:00:00 sshd: rsimms [priv] rsimms :37 ? 00:00:00 sshd: rsimms :37 pts/6 00:00:00 -bash root :07 ? 00:00:00 sshd: dymesdia [priv] dymesdia :08 ? 00:00:00 sshd: dymesdia :08 pts/1 00:00:00 -bash rsimms :15 pts/6 00:00:00 ps -ef lyonsrob Oct01 ? 00:00:00 SCREEN lyonsrob Oct01 pts/3 00:00:00 /bin/bash root Oct15 tty1 00:00:00 /sbin/mingetty tty1 ~]$ 12

13 CIS Lesson 12 Signals

14 CIS Lesson 12 Signals are asynchronous messages sent to processes They can result in one of three courses of action: 1.be ignored, 2.default action (die) 3.execute some predefined function. Signals are sent: Using the kill command: $ kill -# PID Where # is the signal number and PID is the process id. if no number is specified, SIGTERM is sent. Using special keystrokes limited to just a few signals Use kill –l to see all signals Signals

15 CIS Lesson 12 /home/cis90/roddyduk $ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX /home/cis90/roddyduk $ Signals Use kill –l to see all of them

16 CIS Lesson 12 Signals Special keystrokes /home/cis90/roddyduk $ stty -a speed baud; rows 26; columns 78; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^F; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; ~]$ stty -a speed baud; rows 39; columns 84; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; use stty –a to see special keystrokes

17 CIS Lesson 12 System Monitoring uptime Uptime shows how long the system has been running 17

18 CIS Lesson 12 System Monitoring top Use top to find CPU hogs and memory leaks 18

19 CIS Lesson 12 System Monitoring top Use top to find CPU hogs and memory leaks 19 for the past 1, 5 and 15 minutes PR = priority NI = nice values VIRT=Virtual memory used RES=Physical memory used SHR=Shared memory used

20 CIS Lesson 12 System Monitoring top Use top to find CPU hogs and memory leaks 20 for the past 1, 5 and 15 minutes PR = priority NI = nice values VIRT=Virtual memory used RES=Physical memory used SHR=Shared memory used

21 CIS Lesson 12 System Monitoring top Running Jim's cpu.sh script (uses binary calculator) 21 binary calculator

22 CIS Lesson 12 System Monitoring top Running Jim's disk.sh script (lots of find commands) 22

23 CIS Lesson 12 System Monitoring top Running Jim's sleep script 23

24 CIS Lesson 12 System Monitoring vmstat Procs r: The number of processes waiting for run time. b: The number of processes in uninterruptible sleep. Memory swpd: the amount of virtual memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option) Swap si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s). IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s). System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux , this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux , included in idle. st: Time stolen from a virtual machine. Prior to Linux , unknown. 24

25 CIS Lesson 12 scheduling 25

26 CIS Lesson 12 System Monitoring Scheduling Jobs at cron anacron 26

27 CIS Lesson 12 at 27

28 CIS Lesson 12 at command So that the multiprocessing CPU on a UNIX system does not get overloaded, some processes need to be run during low peak hours such as early in the morning or later in the day. The at command is for this purpose. The at command reads its stdin for a list of commands to run, and begins running them at the time of day specified as the first argument: $ at 10:30pm < batch_file $ at 11:59pm at> cat files.out bigshell > lab08 at> cp lab08 /home/rsimms/cis90/$LOGNAME at> Ctrl-D $ Note: the Ctrl-d must be entered as the first character on the last line. Use the at command to schedule a command or script to run in the future 28

29 CIS Lesson 12 Load Balancing Several ways to specify a future time to run This job makes a backup of myscript and sends an when finished Use the atq command to show queued jobs 29

30 CIS Lesson 12 Load Balancing The atrm command is used to remove jobs from the queue The jobs command lists processes running or suspended in the background. The atq command lists jobs queued to run in the futures that were scheduled by at command 30

31 CIS Lesson 12 cron 31

32 CIS Lesson 12 System Monitoring Scheduling Batch (cron) Jobs cron - Scheduling Program that executes tasks at a given time crontab - a program that submits tasks to the cron daemon crontab filename - registers your cron file crontab -l - displays your current cron file crontab -r - removes your current cron file crontab -u user - sets a cron job for another user Crontab service can be denied or allowed on a per/user basis crond cron daemon examines crontab files and at command files. 32

33 CIS Lesson 12 cron crond's parent is init crond daemon lives in /usr/sbin service command can be used to stop and start (Red Hat family) checkcfg command can be used to configure startup by run level 33

34 CIS Lesson 12 System Monitoring Scheduling Batch (cron) Jobs Two cron options: "System" cron jobs Uses /etc/crontab (has additional user field) No need to edit cron files just drop new jobs in: /etc/cron.daily/ /etc/cron.weekly/ /etc/cron.monthly/ Fortified with anacron "User" cron jobs Uses cron files kept in /var/spool/cron Use crontab commands to create, view, and remove cron files One cron file per user (multiple entries for multiple jobs) 34

35 CIS Lesson 12 System cron jobs ~]# ls /etc/cron* /etc/cron.deny /etc/crontab /etc/cron.d: sa-update /etc/cron.daily: 0anacron cups makewhatis.cron prelink tmpwatch 0logwatch logrotate mlocate.cron rpm /etc/cron.hourly: /etc/cron.monthly: 0anacron /etc/cron.weekly: 0anacron makewhatis.cron ~]# ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly * * root run-parts /etc/cron.monthly ~]# Note: 0anacron is the first job to run in each cron directory. anacron complements cron by handling jobs that were scheduled to run when the system was down. spam assassin cron file Has additional user field 35

36 CIS Lesson 12 Create a cron job with the crontab –e command which uses vi Creating user cron jobs Option 1 36

37 CIS Lesson 12 Create a cron job with vi then register it Creating user cron jobs Option 2 37

38 CIS Lesson ,6,9,12 * /root/bin/script1 Min Hr Day Month Weekday Job At 8:30 AM, on the first day of every quarter User cron jobs Note: No user field like in /etc/crontab FieldValue Range Min00-60 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition 38

39 CIS Lesson * * 6 /root/bin/script1 At 10:30 AM every Saturday User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 39

40 CIS Lesson * * 1-5 /root/bin/script1 At 10:30 AM week days Monday through Friday User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 40

41 CIS Lesson 12 0,10,20,30,40,50 * 5 5 * /root/bin/script1 script1 runs every 10 minutes on May 5th User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 41

42 CIS Lesson 12 */5 * * * * /root/bin/script1 script1 runs every 5 minutes User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 42

43 CIS Lesson 12 */10 * * * * /root/bin/script1 script1 runs every 10 minutes User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 43

44 CIS Lesson * /root/bin/script1 31,32, * /root/bin/script2 On April 1 st, script1 is run at 7:30AM followed by script2 running at 7:31AM, 7:32AM and 7:33AM User cron jobs FieldValue Range Min00-59 Hr00-23 Day01-31 Month01-12 Weekday0-6 (0=Sunday) Time value optionDescription nSingle time event n,m,oMultiple time events n-mRange of time events */nRepetition Min Hr Day Month Weekday Job 44

45 CIS Lesson * * * /root/bin/script >> /root/script.log 2>& */2 * * /root/bin/script >> /root/script.log 2>&1 0 8 * * 1-5 /root/bin/script >> /root/script.log 2>& * /root/bin/script >> /root/script.log 2>&1 Everyday at 10 minutes past midnight Every other day at 6:00 PM Weekdays at 8:00 AM Noon on the 4 th of July User cron jobs Min Hr Day Month Weekday Job 45

46 CIS Lesson 12 */2 * * * * echo `date` "To file" >> /root/crontest */2 * * * * echo `date` "To " stdout and stderr get ed if not redirected User cron jobs Where does job output go ????????????? 46

47 CIS Lesson 12 ~]# ls -l /var/spool/cron total 2 -rw root root 127 Nov 29 08:29 root ~]# cat /var/spool/cron/root * * * * * echo "Every minute: " `date` >> /root/crontest-1 */2 * * * * echo "Every 2 minutes: " `date` >> /root/crontest-2 ~]# ~]# crontab -l * * * * * echo "Every minute: " `date` >> /root/crontest-1 */2 * * * * echo "Every 2 minutes: " `date` >> /root/crontest-2 ~]# crontab –l lists the user's cron jobs User cron jobs are stored in /var/spool/cron/ by user name User cron jobs 47

48 CIS Lesson 12 crontab –r will delete a user' s cron configuration file User cron jobs 48

49 CIS Lesson 12 Linux lets anyone run cron jobs. You can use /etc/cron.allow and /etc/cron.deny to manage as necessary. Add users, one per line. If there is a conflict, the most restrictive will apply User cron jobs 49

50 CIS Lesson 12 Create a cron file as root to perform a backup of the /home file system. Do a full level 0 backup, followed by 3 level 1 backups, followed by 3 level 2 backups. Backup example ~]# mkdir -p /backup/level0 /backup/level1 /backup/level2 ~]# vi cron ~]# cat cron 30 7 * * * /sbin/dump 0uf /backup/level0/backup-L0-`date +\%Y-\%d-\%m`.dmp /home * * * /sbin/dump 1uf /backup/level1/backup-L1-`date +\%Y-\%d-\%m`.dmp /home * * * /sbin/dump 2uf /backup/level2/backup-L2-`date +\%Y-\%d-\%m`.dmp /home ~]# crontab cron ~]# crontab -l 30 7 * * * /sbin/dump 0uf /backup/level0/backup-L0-`date +\%Y-\%d-\%m`.dmp /home * * * /sbin/dump 1uf /backup/level1/backup-L1-`date +\%Y-\%d-\%m`.dmp /home * * * /sbin/dump 2uf /backup/level2/backup-L2-`date +\%Y-\%d-\%m`.dmp /home ~]# Note, for demonstration purposes we are doing the backups every minute rather than everyday. escapes needed User cron jobs 50

51 CIS Lesson 12 Backup example continued ~]# mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/root": 7 messages 7 new >N 1 Mon Dec 1 07:30 41/1749 "Cron /sbin/dump 0uf /backu" N 2 Mon Dec 1 07:31 42/1807 "Cron /sbin/dump 1uf /backu" N 3 Mon Dec 1 07:32 42/1807 "Cron /sbin/dump 1uf /backu" N 4 Mon Dec 1 07:33 42/1807 "Cron /sbin/dump 1uf /backu" N 5 Mon Dec 1 07:34 42/1807 "Cron /sbin/dump 2uf /backu" N 6 Mon Dec 1 07:35 42/1807 "Cron /sbin/dump 2uf /backu" N 7 Mon Dec 1 07:36 42/1807 "Cron /sbin/dump 2uf /backu" & Backups results are ed User cron jobs 51

52 & 1 Message 1: From Mon Dec 1 07:30: Date: Mon, 1 Dec :30: From: (Cron Daemon) To: Subject: Cron /sbin/dump 0uf /backup/level0/backup-L0-`date +%Y-%d-%m`.dmp /home Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated X-Cron-Env: DUMP: Date of this level 0 dump: Mon Dec 1 07:30: DUMP: Dumping /dev/sda7 (/home) to /backup/level0/backup-L dmp DUMP: Label: /home DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 90 blocks. DUMP: Volume 1 started with block 1 at: Mon Dec 1 07:30: DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /backup/level0/backup-L dmp DUMP: Volume 1 completed at: Mon Dec 1 07:30: DUMP: Volume blocks (0.15MB) DUMP: 150 blocks (0.15MB) on 1 volume(s) DUMP: finished in less than a second DUMP: Date of this level 0 dump: Mon Dec 1 07:30: DUMP: Date this dump completed: Mon Dec 1 07:30: DUMP: Average transfer rate: 0 kB/s DUMP: DUMP IS DONE & CIS Lesson 12 This is an of the level 0 backup Backup example continued 52

53 CIS Lesson 12 Note: After the backup jobs have been run, the dump files appear in the appropriate directories The last dumps for each level recorded here User cron jobs Backup example continued 53

54 CIS Lesson 12 date command BTW, Here is how you set the system date and time 54

55 CIS Lesson 12 System Monitoring Process Management ps Provides snapshot of all system processes uptime Can be used as indication of systematic degredation top Interaction version of ps with additional summary info vmstat Provides snapshot of overall memory 55


Download ppt "CIS 191 - Lesson 12 System Monitoring 1. CIS 191 - Lesson 12 ps command 2."

Similar presentations


Ads by Google