Software Layers 2 Introduction to unix 2


Process Monitoring: ps, time, which



Download 0.58 Mb.
Page6/26
Date28.01.2017
Size0.58 Mb.
#10070
1   2   3   4   5   6   7   8   9   ...   26

Process Monitoring: ps, time, which


  • p
    The outputs are:

    • PID: Process Id (a unique number)

    • TTY: the text window

    • S: the state of the process

    • TIME: process runtime

    • CMD: the text cmd that started the process

    The other outputs (for the -f option) are:

    • UID: User Id (account name)

    • PPID: Parent Process Id (also unique)

    • C: the process CPU usage (%)

    • STIME: the process start time
    s
     views current processes

  • ps -f  views full details of current processes

eg:

% ps

PID TTY S TIME CMD

1001 ttyx6 S 0:00.37 -sh (tcsh)

15411 ttyx6 I 0:00.01 sh -c /bin/sh -c /local/user/.menu

18870 ttyx6 I 0:00.01 /bin/sh -c /local/user/.menu

23641 ttyx6 I 0:00.30 /local/bin/menuaccess

% ps -f

UID PID PPID C STIME TTY TIME CMD



sci-jjh 101 23515 0.0 09:56:53 ttyx6 0:00.38 -sh (tcsh)

sci-jjh 1541 23641 0.0 09:56:50 ttyx6 0:00.01 sh -c /bin/sh -c/local

sci-jjh 1880 15411 0.0 09:56:51 ttyx6 0:00.01 /bin/sh -c/local/user/

sci-jjh 2361 22646 0.0 09:56:33 ttyx6 0:00.30

/local/bin/menuaccess

%



note: PID & PPID are unique  system can identify & control all processes

note: CPU usages are mostly 0, because when the ps process is running, most other processes stopped


  • time  determines the time a cmd takes to execute.

There are two forms:

  • time  a built-in cmd

  • /usr/bin/time  separate executable program

eg:

>
The output format for time is: U S E P X+D I+O F+W

For our purposes, the main ones are:



  • U  user time (CPU seconds not including system calls)

  • S  system time (CPU seconds for system calls only)

  • E  elapse time (overall time to run the process)

  • P  user and system time as a percentage of elapse time

For /usr/bin/time the outputs are:

  • real  the overall time in seconds

  • user  the user time (U)

  • sys  the system time (S)
time ps -f

UID PID PPID C STIME TTY TIME CMD

sci-jjh 6502 20278 0.0 15:38:55 ttyt5 0:00.04 /local/bin/menu

access.


sci-jjh 14495 6502 0.0 15:38:57 ttyt5 0:00.37 -sh (tcsh)

sci-jjh 19498 23668 0.0 15:38:55 ttyt5 0:00.01 sh -c /bin/sh -c

/local

sci-jjh 20278 19498 0.0 15:38:55 ttyt5 0:00.01 /bin/sh -c


> /usr/bin/time ps -f

UID PID PPID C STIME TTY TIME CMD

sci-jjh 4116 14495 0.0 16:30:17 ttyt5 0:00.01 /usr/bin/time ps -f

sci-jjh 6502 20278 0.0 15:38:55 ttyt5 0:00.04 /local/bin/menu

access.

sci-jjh 14495 6502 0.0 15:38:57 ttyt5 0:00.38 -sh (tcsh)



sci-jjh 19498 23668 0.0 15:38:55 ttyt5 0:00.01 sh -c /bin/sh -c

/local
real 0.2

user 0.0

sys 0.1




  • which  displays the absolute pathname of a program. (useful if several versions exist)

eg: on barra ps has two versions: /sbin/ps & /usr/bin/ps

% whereis ps

ps: /sbin/ps /usr/bin/ps

% which ps

/usr/bin/ps

%


So in this case, /usr/bin/ps is used.


Process Control Commands: kill, fg, bg, nice


For a currently active process:

  • ^C  (control-c) terminates the process

  • ^Z  suspends the process




  • kill
    terminates process corresponding to PID

eg: Lets say we are looking at a file called summary using the cmd less:

% less summary

if test $# != 1

then echo 'wrong number of arguments'

else cd $1

set - *

……………


We type ^Z to suspend less summary  then use ps to see PID’s  & then we can kill that process

Suspended

% ps


PID TTY S TIME CMD

1001 ttyx6 S 0:00.42 -sh (tcsh)

15411 ttyx6 I 0:00.01 sh -c /bin/sh -c /local/user/.menu

24864 ttyx6 T 0:00.02 less summary

% kill 24864

[1] Terminated less summary

%




  • bg  places most recently suspended process into background (still running, but without control of text window) note: To start a process in background, add & to the end of cmd

  • fg  restores most recent background process to foreground (has control of text window)




  • nice  runs a cmd slowly (useful if cmd requires lots of CPU time)

note: Using nice will allow other processes more CPU time  this is a CPU-intensive cmd

eg. nice ps aux  makes ps aux run slowly



Download 0.58 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   26




The database is protected by copyright ©ininet.org 2024
send message

    Main page