From e3a90c20046c33bb77f715b31007b26aadd9b3e3 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 18 Oct 2011 20:45:37 -0400 Subject: adding more to the 'ps' section of chapter_06 --- chapter_06.xml | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/chapter_06.xml b/chapter_06.xml index 785f4da..0b02a4b 100644 --- a/chapter_06.xml +++ b/chapter_06.xml @@ -94,7 +94,50 @@ is consuming when ps is run. -Finally, ps can also create a process tree. +To accomplish bits of this, on a per process basis, ps allows +one or more process IDs (PIDs) to be provided in the command line, and has the '-o' flag +to show a particular attribute of the PID. + + +darkstar:~$ ps -o cmd -o etime $$ +CMD ELAPSED +/bin/bash 12:22 + + + +What this is displaying, is the PID's command name (cmd), and its elapsed time (etime). +The PID in this example, is a shell variable for the PID of the current shell. So you +can see, in this example, the shell process has existed for 12 minutes, 22 seconds. + + + +Using the pgrep(1) command, this can get more automatable. + + +darkstar:~$ ps -o cmd -o rss -o vsz $(pgrep httpd) +CMD RSS VSZ +/usr/sbin/httpd -k restart 33456 84816 +/usr/sbin/httpd -k restart 33460 84716 +/usr/sbin/httpd -k restart 33588 84472 +/usr/sbin/httpd -k restart 30424 81608 +/usr/sbin/httpd -k restart 33104 84900 +/usr/sbin/httpd -k restart 33268 85112 +/usr/sbin/httpd -k restart 30640 82724 +/usr/sbin/httpd -k restart 15168 67396 +/usr/sbin/httpd -k restart 33180 84416 +/usr/sbin/httpd -k restart 33396 84592 +/usr/sbin/httpd -k restart 32804 84232 + + + +In this example, a subshell execution, using pgrep, +is returning the PIDs of any process, whose command +name includes 'httpd'. Then ps displaying the command name, +resident memory size, and virtual memory size. + + + +Finally, ps can also create a process tree. This shows you which processes have children processes. Ending the parent of a child process also ends the child. We do this with the -ejH argument. @@ -115,12 +158,36 @@ parent of a child process also ends the child. We do this with the -As you can see, ps is an incredibly powerful +As you can see, ps(1) is an incredibly powerful tool for determining not only what processes are currently active on your system, but also for learning lots of important information about them. + +As is the case with many of the applications, there is often several tools +for the job. Similar to the ps -ejH output, but more terse, +is pstree(1). It displays the process tree, a bit more visually. + + +darkstar:~$ pstree +init-+-atd + |-crond + |-dbus-daemon + |-httpd---10*[httpd] + |-inetd + |-klogd + |-mysqld_safe---mysqld---8*[{mysqld}] + |-screen-+-4*[bash] + | |-bash---pstree + | |-2*[bash---ssh] + | `-bash---irssi + |-2*[sendmail] + |-ssh-agent + |-sshd---sshd---sshd---bash---screen + `-syslogd + +
@@ -130,7 +197,7 @@ them. Managing processes isn't only about knowing which ones are running, but also about communicating with them to change their behavior. The most common way of managing a program is to terminate it. Thus, the tool for -the job is named kill(1). Despite the name, +the job is named kill(1). Despite the name, kill doesn't actually terminate processes, but sends signals to them. The most common signal is a SIGTERM, which tells the process to finish up what it is doing and terminate. There -- cgit v1.2.3