===== Controlling Processes ===== * process priorities * normal user process priorities range from 0-19 * called "niceness" of a process, where 0 is normal and 19 is nicest * root and user can control priority of processes * root process priorities range from -20 to 19. * See //man nice// * view most resource intensive processes with //top// * control priorities with //nice// / //renice// commands * use //nice// to start processes with a certain priority * use //renice// to set priority of already-running process * finding processes * //pgrep//, //ps aux | grep [string]// * terminating processes (UNIX) * kill PID * pkill [process name pattern] * using signals (most commonly used signals in UNIX //kill// command) * //kill -HUP PID// or //kill -1 PID// forces a //hangup//, causing some processes to reload and re-read their configuration * //kill -KILL PID// or //kill -9 PID// causes immediate, unclean termination of process * May use if normal //kill PID// or //pkill [process name pattern]// does not work * normal, default signal is SIGTERM * See output of //kill -L//. ==== Viewing and debugging processes ==== * strace, dtrace, SystemTap * Install the //strace// package on your Linux systems if you don't have it. * //strace// is a tool for tracing system calls and signals. * Intercepts and records the system calls made by a running process. * Can print a record of each system call, its arguments, and its return value. * Often useful in instances where a program freezes or otherwise fails to work and offers few obvious clues as to the problem. * Examples: # Shows system calls made by running 'hostname' $ strace hostname # Shows what files are opened when running 'who' $ strace -e open who # Attach to an already running process; useful for watching # daemons in action: $ ps aux | grep ssh root 1243 0.0 0.1 5488 968 ? Ss Mar12 0:00 /usr/sbin/sshd ... # Attach strace to the running /usr/sbin/sshd process by its PID (1243), # and watch the output as someone logs in via ssh: $ strace -p 1243 * //lsof// * a command meaning "list open files", which is used in many UNIX-like systems to report a list of all open files and the processes that opened them. * Open files in the system include disk files, pipes, network sockets and devices opened by all processes. * One use for this command is for when a disk cannot be unmounted because unknown files are in use. * Example: # Shows all open files owned by jchung # (generally should run lsof as root) $ lsof | grep jchung | less * Controlling process output verbosity * Well-written programs and daemons include options to include extra information in output to facilitate debugging and performance analysis. * Example: ssh -v (verbose mode) * ssh -vv, ssh -vvv (extra verbose modes) ---- ===== Lab Activity ===== ==== Strace ==== On your Linux virtual machines, what do you see when you $ ping # example: $ ping richardson ? Run //strace// on your Linux virtual machines to investigate how //ping// goes about finding an IP address associated with your system hostname to send //ping// packets to. Force //ping// to send just one //ping// packet, and force //strace// to send its output to a file called //strace.out//, so that you can look at //strace// output offline. ----