Unit 7 Solaris Process Control Randy Marchany VA

  • Slides: 12
Download presentation
Unit 7 – Solaris Process Control Randy Marchany VA Tech Computing Center

Unit 7 – Solaris Process Control Randy Marchany VA Tech Computing Center

ps w The ps command lists processes running on the system. w Without arguments,

ps w The ps command lists processes running on the system. w Without arguments, the command only shows the processes run by the current user. w Solaris has 2 versions of the ps command. /usr/ucb/ps and /usr/bin/ps. /usr/ucb/ps is the BSD version of the command.

ps w ps –ef will list all of the processes running on the system.

ps w ps –ef will list all of the processes running on the system. w Every process is assigned a unique number (PID). w The CMD field of the output lists the actual command running on the system. w There a lot of other fields

ps w ps –el will list the process states as well. – O –

ps w ps –el will list the process states as well. – O – the process is currently running. Note, this will almost always be the ps command itself. – S – the process is sleeping, waiting for resources or input. – R – the process is runnable and in the run queue. – Z – the process is in a Zombie state and can only be cleared by a reboot. This occurs when a child process dies ant the parent fails to clean up after it. – T – process is stopped by job control. A ctl-Z will put a process in this state.

prstat w prstat command shows the running processes at a configured interval (5 seconds).

prstat w prstat command shows the running processes at a configured interval (5 seconds). w Can sort the output by key values supplied by the –s option – – – Cpu – sort by cpu usage Time – sort by process execution time Size – sort by process image size Rss – sort by process resident set size Pri – sort by process priority

Killing a Process w Sometimes you have to kill a runaway process. w The

Killing a Process w Sometimes you have to kill a runaway process. w The kill command will do this but you must specify a signal value. This signal tells the process to do something. w Solaris has 42 different signals that can be sent to a process. We’ll only look at 3 of them: 1, 3, 9.

Killing a Process w Trapping Signals – A process can do 3 things when

Killing a Process w Trapping Signals – A process can do 3 things when it receives a signal: • Ignore the signal • Do something like close all open files and exiting • Do what the signal tells it to do w If the process has a ‘signal handler’, then it can intercept the signal and do what the handler wants with it.

Killing a Process w The psig command (new to Solaris 8) will print a

Killing a Process w The psig command (new to Solaris 8) will print a list showing what the process’ response will be to each of the 47 different signals. w There are 2 signals which can’t be ignored. – 9 – aka SIGKILL forces a process to release its resources and die. This could cause corruption of data if the process is I/O intensive.

Killing a Process w The second signal that can’t be ignored: – 23 –

Killing a Process w The second signal that can’t be ignored: – 23 – aka SIGSTOP. This is used in shell-based job control and is invoked when you hit a ^Z. Solaris 8 provides a pstop command which does the same thing. – To resume the process, use the prun command to restart the process from its suspended state.

Setting Process Priority w The ‘nice’ command allows the administrator to change the priority

Setting Process Priority w The ‘nice’ command allows the administrator to change the priority of a running process. w Default nice value is 20. Do a ‘ps –elf’ and look at the NI field. w Nice values range from 0 -39. But they are the number to be added to the default value of 20. Example: nice –n 10 PID will set the nice value to 30. You can use negative numbers to lower the priority. The renice command works on running processes.

Common Signals You want to gracefully kill a process Send SIGTERM (15) to the

Common Signals You want to gracefully kill a process Send SIGTERM (15) to the process (kill – 15 pid) You want to suspend a process not kill it Hit ^Z or kill – 23 pid Process refuses to respond to a 1, 2 or 15 Kill – 9 pid Suspended process needs Send SIGCONT(25) to be restarted

Killing a Process w To see all the values for the kill command, enter:

Killing a Process w To see all the values for the kill command, enter: kill –l w To send a signal, enter: kill –s signal# pid OR kill –signal pid w Example: – Kill – 3 pid w pgrep command retrieves the PID of a process.