<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>DB2 学习笔记</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/" />
    <link rel="self" type="application/atom+xml" href="http://www.aiview.com/index.xml" />
    <id>tag:www.aiview.com,2006-12-14://1</id>
    <updated>2007-01-12T19:12:25Z</updated>
    <subtitle>博客话题：DB2，Linux，Web，业余无线电，户外，摄影，截拳道，Thankpad，其他</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.261</generator>

<entry>
    <title>Using &quot;ps&quot; shell command</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/12/using_ps_shell_command.html" />
    <id>tag:blog.alex.com,2006://1.857</id>

    <published>2006-12-28T12:04:20Z</published>
    <updated>2007-01-12T19:12:25Z</updated>

    <summary><![CDATA[Here's a normal output from ps command with -ef parameters./home/zhangy/&gt; ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Dec 03 - 13:32 /etc/init root 3932 1 0 Dec 03 - 0:01 /usr/lib/errdemon root 4670...]]></summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Linux" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="ps" label="ps" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<p>Here's a normal output from ps command with -ef parameters.</p><pre class="output">/home/zhangy/&gt; ps -ef<br />     UID    PID   PPID   C    STIME    TTY  TIME CMD<br />    root      1      0   0   Dec 03      - 13:32 /etc/init<br />    root   3932      1   0   Dec 03      -  0:01 /usr/lib/errdemon<br />    root   4670      1   1   Dec 03      - 416:09 /usr/sbin/syncd 60<br />    root   5196   7498   0   Dec 03      -  0:06 /usr/local/sbin/sshd<br />    ...<br /></pre><ul><li>-e: Print all processes info except kernel processes.<br /> </li><li>-f: Here tells ps to show user name instead of user id at UID and to show parameters for command at CMD.</li></ul>The explanation for each column.<br /><ul><li>UID: The user who kicked off the process</li><li>PID: The process ID of the process</li><li>PPID: The process ID of the parent process</li><li>C: Usage of CPU<br /></li><li>STIME: The starting time of the process</li><li>TTY: <br /></li><li>TIME: The total run time of the process<br /></li><li>CMD: The command with parameters and its full path</li></ul><h4>Tips</h4><p>We use <span class="emphasis">PID and PPID</span> to track process tree. For killing any process, we should refer to PID. To track PPID we could kill a group of related processes.</p><p><span class="emphasis">STIME </span>is very helpful to indicate the multi-process with the same script name. Usually they have different run time.</p><p><span class="emphasis">CMD </span>is also helpful to get command name and path.&nbsp;</p><h4>Reference&nbsp;</h4><p>A full reference on column explaination from unix <span class="emphasis">man </span>page.</p><pre class="output">ADDR<br />  (-l and l flags) Contains the segment number of the process stack, if normal;<br />  if a kernel process, the address of the preprocess data area.<br /><br />BND<br />  (-o THREAD flag) The logical processor number of the processor to which the<br />  kernel thread is bound (if any). For a process, this field is shown if all its<br />  threads are bound to the same processor.<br /><br />C<br />  (-f, l, and -l flags) CPU utilization of process or thread, incremented each<br />  time the system clock ticks and the process or thread is found to be running.<br />  The value is decayed by the scheduler by dividing it by 2 once per second. For<br />  the sched_other policy, CPU utilization is used in determining process<br />  scheduling priority. Large values indicate a CPU intensive process and result<br />  in lower process priority whereas small values indicate an I/O intensive<br />  process and result in a more favorable priority.<br /><br />CMD<br />  (-f, -l, and l flags) Contains the command name. The full command name and its<br />  parameters are displayed with the -f flag.<br /><br />COMMAND<br />  (s, u, and v) Contains the command name. The full command name and its<br />  parameters are displayed with the -f flag.<br /><br />  F Field Table<br /><br />  Flags Hexadecimal Value Definition<br /><br />  SLOAD 0x00000001 Indicates that the process is operating in core memory.<br /><br />  SNOSWAP 0x00000002 Indicates that the process cannot be swapped out.<br /><br />  STRC 0x00000008 Indicates that the process is being traced.<br /><br />  SWTED 0x00000010 Indicates that the process stopped while being traced.<br /><br />  SFWTED 0x00000020 Indicates that the process stopped after a call to the fork<br />  subroutine, while being traced.<br /><br />  SEWTED 0x00000040 Indicates that the process stopped after a call to the exec<br />  subroutine, while being traced.<br /><br />  SLWTED 0x00000080 Indicates that the process stopped after a call to the load<br />  or unload subroutine, while being traced.<br /><br />  SFIXPRI 0x00000100 Indicates that the process has a fixed priority, ignoring<br />  the pcpu field descriptor.<br /><br />  SKPROC 0x00000200 Indicates a Kernel process.<br /><br />  SOMASK 0x00000400 Indicates restoration of the old mask after a signal is<br />  received.<br /><br />  SWAKEONSIG 0x00000800 Indicates that the signal will abort the sleep<br />  subroutine. The contents must not be equal to those of the PCATCH flag. The<br />  contents of both PCATCH and SWAKEONSIG must be greater than those of PMASK.<br /><br />  SUSER 0x00001000 Indicates that the process is in user mode.<br /><br />  SLKDONE 0x00002000 Indicates that the process has done locks.<br /><br />  STRACING 0x00004000 Indicates that the process is a debugging process.<br /><br />  SMPTRACE 0x00008000 Indicates multi-process debugging.<br /><br />  SEXIT 0x00010000 Indicates that the process is exiting.<br /><br />  SSEL 0x00020000 Indicates that the processor is selecting: wakeup/waiting<br />  danger.<br /><br />  SORPHANPGRP 0x00040000 Indicates an orphaned process group.<br /><br />  SNOCNTLPROC 0x00080000 Indicates that the session leader relinquished the<br />  controlling terminal.<br /><br />  SPPNOCLDSTOP 0x00100000 Indicates that the SIGHLD signal is not sent to the<br />  parent process when a child stops.<br /><br />  SEXECED 0x00200000 Indicates that process has been run.<br /><br />  SJOBSESS 0x00400000 Indicates that job control was used in the current<br />  session.<br /><br />  SJOBOFF 0x00800000 Indicates that the process is free from job control.<br /><br />  PSIGDELIVERY 0x01000000 Indicates that the process is used by the<br />  program-check handler.<br /><br />  SRMSHM 0x02000000 Indicates that the process removed shared memory during a<br />  call to the exit subroutine.<br /><br />  SSLOTFREE 0x04000000 Indicates that the process slot is free.<br /><br />  SNOMSG 0x08000000 Indicates that there are no more uprintf subroutine<br />  messages.<br /><br />F<br />  (-l and l flags) Some of the more important F field flags (hexadecimal and<br />  additive) associated with processes and threads are shown below:<br /><br />  F Field Table<br /><br />  Flags Hex Value Definition<br /><br />  SLOAD 0x00000001 Indicates that the process is operating in core memory.<br /><br />  SNOSWAP 0x00000002 Indicates that the process cannot be swapped out.<br /><br />  STRC 0x00000008 Indicates that the process is being traced.<br /><br />  SKPROC 0x00000200 Indicates a kernel process.<br /><br />  SEXIT 0x00010000 Indicates that the process is exiting.<br /><br />  SEXECED 0x00200000 Indicates that the process has been run.<br /><br />  SEXECING 0x01000000 Indicates that the process is execing (performing an<br />  exec).<br /><br />  TKTHREAD 0x00001000 Indicates that the thread is a kernel-only thread.<br /><br />    Note: You can see the definitions all process and thread flags by consulting<br />    the p_flags and t_flags fields in the /usr/include/sys/proc.h and<br />    /usr/include/sys/thread.h files respectively.<br /><br />LIM<br />  (v flag) The soft limit on memory used, specified via a call to the setrlimit<br />  subroutine. If no limit has been specified, then shown as xx. If the limit is<br />  set to the system limit, (unlimited), a value of UNLIM is displayed.<br /><br />NI<br />  (-l and l flags) The nice value; used in calculating priority for the sched<br />  other policy.<br /><br />PID<br />  (all flags) The process ID of the process.<br /><br />PGIN<br />  (v flag) The number of disk I/Os resulting from references by the process to<br />  pages not loaded in core.<br /><br />PPID<br />  (-f, l, and -l flags) The process ID of the parent process.<br /><br />PRI<br />  (-l and l flags) The priority of the process or kernel thread ; higher numbers<br />  mean lower priority.<br /><br />RSS<br />  (v flag) The real-memory (resident set) size of the process (in 1KB units).<br /><br />S<br />  (-l and l flags) The state of the process or kernel thread :<br /><br />  For processes:<br /><br />  O<br />    Nonexistent<br /><br />  A<br />    Active<br /><br />  W<br />    Swapped<br /><br />  I<br />    Idle (waiting for startup)<br /><br />  Z<br />    Canceled<br /><br />  T<br />    Stopped<br /><br />  For kernel threads:<br /><br />  O<br />    Nonexistent<br /><br />  R<br />    Running<br /><br />  S<br />    Sleeping<br /><br />  W<br />    Swapped<br /><br />  Z<br />    Canceled<br /><br />  T<br />    Stopped<br /><br />SC<br />  (-o THREAD flag) The suspend count of the process or kernel thread. For a<br />  process, the suspend count is defined as the sum of the kernel threads suspend<br />  counts.<br /><br />SCH<br />  (-o THREAD flag) The scheduling policy for a kernel thread. The policies<br />  sched_other, sched_fifo, and sched_rr are respectively displayed using: 0, 1,<br />  2.<br /><br />SIZE<br />  (v flag) The virtual size of the data section of the process (in 1KB units).<br /><br />SSIZ<br />  (s flag) The size of the kernel stack. This value is always 0 (zero) for a<br />  multi-threaded process.<br /><br />STAT<br />  (s, u, and v flags) Contains the state of the process:<br /><br />  0<br />    Nonexistent<br /><br />  A<br />    Active<br /><br />  I<br />    Intermediate<br /><br />  Z<br />    Canceled<br /><br />  T<br />    Stopped<br /><br />  K<br />    Available kernel process<br /><br />STIME<br />  (-f and u flags) The starting time of the process. The LANG environment<br />  variables control the appearance of this field.<br /><br />SZ<br />  (-l and l flags) The size in 1KB units of the core image of the process.<br /><br />THCNT<br />  (-o thcount flag) The number of kernel threads owned by the process.<br /><br />TID<br />  (-o THREAD flag) The thread ID of the kernel thread.<br /><br />TIME<br />  (all flags) The total execution time for the process.<br /><br />TRS<br />  (v flag) The size of resident-set (real memory) of text.<br /><br />TSIZ<br />  (v flag) The size of text (shared-program) image.<br /><br />TTY<br />  (all flags) The controlling workstation for the process:<br /><br />  -<br />    The process is not associated with a workstation.<br /><br />  ?<br />    Unknown.<br /><br />  Number<br />    The TTY number. For example, the entry 2 indicates TTY2.<br /><br />UID<br />  (-f, -l, and l flags) The user ID of the process owner. The login name is<br />  printed under the -f flag.<br /><br />USER<br />  (u flag) The login name of the process owner.<br /><br />WCHAN<br />  (-l flag) The event for which the process or kernel thread is waiting or<br />  sleeping. For a kernel thread, this field is blank if the kernel thread is<br />  running. For a process, the wait channel is defined as the wait channel of the<br />  sleeping kernel thread if only one kernel thread is sleeping; otherwise a star<br />  is displayed.<br /><br />WCHAN<br />  (l flag) The event on which process is waiting (an address in the system). A<br />  symbol is chosen that classifies the address, unless numerical output is<br />  requested.<br /><br />%CPU<br />  (u and v flags) The percentage of time the process has used the CPU since the<br />  process started. The value is computed by dividing the time the process uses<br />  the CPU by the elapsed time of the process. In a multi-processor environment,<br />  the value is further divided by the number of available CPUs since several<br />  threads in the same process can run on different CPUs at the same time.<br />  (Because the time base over which this data is computed varies, the sum of all<br />  %CPU fields can exceed 100%.)<br /><br />%MEM<br />  (u and v flags) The percentage of real memory used by this process.<br />&nbsp;</pre><p>A full reference on flag parameters from unix <span class="emphasis">man </span>page.</p><pre class="output">Flags<br /><br />The following flags are preceded by a - (minus sign):<br /><br />-A Writes to standard output information about all processes.<br /><br />-a Writes to standard output information about all processes, except the session<br />leaders and processes not associated with a terminal.<br /><br />-c Clist Displays only information about processes assigned to the workload<br />management classes listed in the Clist variable. The Clist variable is either a<br />comma separated list of class names or a list of class names enclosed in double<br />quotation marks (&quot; &quot;), which is separated from one another by a comma or by one<br />or more spaces, or both.<br /><br />-d Writes information to standard output about all processes, except the session<br />leaders.<br /><br />-e Writes information to standard output about all processes, except kernel<br />processes.<br /><br />-F Format Same as -o Format<br /><br />-f Generates a full listing.<br /><br />-G Glist Writes information to standard output only about processes that are in<br />the process groups listed for the Glist variable. The Glist variable is either a<br />comma-separated list of process group identifiers or a list of process group<br />identifiers enclosed in double quotation marks (&quot; &quot;) and separated from one<br />another by a comma or by one or more spaces. This flag is equivalent to the -g<br />Glist flag.<br /><br />-g Glist This flag is equivalent to the -G Glist flag.<br /><br />-k Lists kernel processes.<br /><br />-l Generates a long listing. See also the l flag.<br /><br />-m Lists kernel threads as well as processes. Output lines for processes are<br />followed by an additional output line for each kernel thread. This flag does not<br />display thread-specific fields ( bnd, scount, sched, thcount, and tid), unless<br />the appropriate -o Format flag is specified.<br /><br />-N Gathers no thread statistics. With this flag ps simply reports those<br />statistics that can be obtained by not traversing through the threads chain for<br />the process.<br /><br />-n NameList Specifies an alternative system name-list file in place of the<br />default. The operating system does not use the -n flag, since information is<br />supplied directly to the kernel.<br /><br />-o Format Displays information in the format specified by the Format variable.<br />Multiple field specifiers can be specified for the Format variable. The Format<br />variable is either a comma-separated list of field specifiers or a list of field<br />specifiers enclosed within a set of &quot; &quot; (double-quotation marks) and separated<br />from one another by a comma or by one or more spaces, or both.<br /><br />Each field specifier has a default header. The default header can be overridden<br />by appending an = (equal sign) followed by the user-defined text for the header.<br />The fields are written in the order specified on the command line in column<br />format. The field widths are specified by the system to be at least as wide as<br />the default or user-defined header text. If the header text is null, (such as if<br />-o user= is specified), the field width is at least as wide as the default<br />header text. If all header fields are null, no header line is written.<br /><br />The following field specifiers are recognized by the system:<br /><br />args<br />  Indicates the full command name being executed. All command-line arguments are<br />  included, though truncation may occur. The default header for this field is<br />  COMMAND.<br /><br />bnd<br />  Indicates to which (if any) processor a process or kernel thread is bound. The<br />  default header for this field is BND.<br /><br />class<br />  Indicates the workload management class assigned to the process. the default<br />  header for this field is CLASS.<br /><br />comm<br />  Indicates the short name of the command being executed. Command-line arguments<br />  are not included. The default header for this field is COMMAND.<br /><br />cpu<br />  Determines process scheduling priority. CPU utilization of process or thread,<br />  incremented each time the system clock ticks and the process or thread is<br />  found to be running. The value is decayed by the scheduler by dividing it by 2<br />  once per second. For the sched_other policy, Large values indicate a CPU<br />  intensive process and result in lower process priority whereas small values<br />  indicate an I/O intensive process and result in a more favorable priority.<br /><br />etime<br />  Indicates the elapsed time since the process started. The elapsed time is<br />  displayed in the following format:<br /><br />  [[ dd-]hh:]mm:ss<br /><br />  where dd specifies the number of days, hh specifies the number of hours, mm<br />  specifies the number of minutes, and ss specifies the number of seconds. The<br />  default header for this field is ELAPSED.<br /><br />group<br />  Indicates the effective group ID of the process. The textual group ID is<br />  displayed. If the textual group ID cannot be obtained, a decimal<br />  representation is used. The default header for this field is GROUP.<br /><br />nice<br />  Indicates the decimal value of the process nice value. The default header for<br />  this field is NI.<br /><br />-o Format (Continued)<br /><br />pcpu<br />  Indicates the ratio of CPU time used to CPU time available, expressed as a<br />  percentage. The default header for this field is %CPU.<br /><br />pgid<br />  Indicates the decimal value of the process group ID. The default header for<br />  this field is PGID.<br /><br />pid<br />  Indicates the decimal value of the process ID. The default header for this<br />  field is PID.<br /><br />ppid<br />  Indicates the decimal value of the parent process ID. The default header for<br />  this field is PPID.<br /><br />rgroup<br />  Indicates the real group ID of the process. The textual group ID is displayed.<br />  If the textual group ID cannot be obtained, a decimal representation is used.<br />  The default header for this field is RGROUP.<br /><br />ruser<br />  Indicates the real user ID of the process. The textual user ID is displayed.<br />  If the textual user ID cannot be obtained, a decimal representation is used.<br />  The default header for this field is RUSER.<br /><br />scount<br />  Indicates the suspend count for a kernel thread. The default header for this<br />  field is SC.<br /><br />sched<br />  Indicates the scheduling policy for a kernel thread. The default header for<br />  this field is SCH.<br /><br />tag<br />  Indicates the Workload Manager application tag. The default header for this<br />  field is TAG. The tag is a character string up to 30 characters long and may<br />  be truncated when displayed by ps. For processes which do not set their tag,<br />  this field displays as a hyphen (-).<br /><br />thcount<br />  Indicates the number of kernel threads owned by the process. The default<br />  header for this field is THCNT.<br /><br />-o Format (Continued)<br /><br />THREAD<br />  Indicates the following fields:<br />    o User name (the uname field)<br />    o Process and parent process IDs for processes (the pid and ppid fields)<br />    o Kernel thread ID for threads (the tid field)<br />    o The state of the process or kernel thread (the S field)<br />    o The CPU utilization of the process or kernel thread (the C field)<br />    o The priority of the process or kernel thread (the PRI field)<br />    o The suspend count of the process or kernel thread (the scount field)<br />    o The wait channel of the process or kernel thread (the WCHAN field)<br />    o The flags of the process or kernel thread (the F field)<br />    o The controlling terminal of the process (the tty field)<br />    o The CPU to which the process or kernel thread is bound (the bnd field)<br />    o The command being executed by the process (the comm field).<br /><br />  Threads are not actually displayed with the -o THREAD flag, unless the -m flag<br />  is also specified.<br /><br />tid<br />  Indicates the thread ID of a kernel thread. The default header for this field<br />  is TID.<br /><br />time<br />  Indicates the cumulative CPU time since the process started. The time is<br />  displayed in the following format:<br /><br />  [ dd-]hh:mm:ss<br /><br />  where dd specifies the number of days, hh specifies the number of hours, mm<br />  specifies the number of minutes, and ss specifies the number of seconds. The<br />  default header for this field is TIME.<br /><br />tty<br />  Indicates the controlling terminal name of the process. The default header for<br />  this field is TT.<br /><br />user<br />  Indicates the effective user ID of the process. The textual user ID is<br />  displayed. If the textual user ID cannot be obtained, a decimal representation<br />  is used. The default header for this field is USER.<br /><br />vsz<br />  Indicates, as a decimal integer, the size in kilobytes of the process in<br />  virtual memory. The default header for this field is VSZ.<br /><br />-o Format (Continued)<br /><br />Otherwise, multiple fields in a specified format can be displayed by the Format<br />variable, including field descriptors. If field descriptors are used in the<br />Format variable, it must be enclosed in double quotation marks (&quot; &quot;). The<br />following table shows how field descriptors correspond to field specifiers:<br /><br />Field           Field           Default<br /><br />Descriptors     Specifiers      Headers<br /><br />   %a              args            COMMAND<br /><br />%c              comm            COMMAND<br /><br />%t              etime           ELAPSED<br /><br />%G              group           GROUP<br /><br />%n              nice            NI<br /><br />%C              pcpu            %CPU<br /><br />%r              pgid            PGID<br /><br />%p              pid             PID<br /><br />%P              ppid            PPID<br /><br />%g              rgroup          RGROUP<br /><br />%u              ruser           RUSER<br /><br />%x              time            TIME<br /><br />%y              tty             TTY<br /><br />%U              user            USER<br /><br />%z              vsz             VSZ<br /><br />-p Plist Displays only information about processes with the process numbers<br />specified for the Plist variable. The Plist variable is either a comma separated<br />list of process ID numbers or a list of process ID numbers enclosed in double<br />quotation marks (&quot; &quot;) and separated from one another by a comma or by one or<br />more spaces, or both.<br /><br />-t Tlist Displays only information about processes associated with the<br />workstations listed in the Tlist variable. The Tlist variable is either a comma<br />separated list of workstation identifiers or a list of workstation identifiers<br />enclosed in double quotation marks (&quot; &quot;) and separated from one another by a<br />comma or by one or more spaces, or both.<br /><br />-U Ulist Displays only information about processes with the user ID numbers or<br />login names specified for the Ulist variable. The Ulist variable is either a<br />comma-separated list of user IDs or a list of user IDs enclosed in double<br />quotation marks (&quot; &quot;) and separated from one another by a comma and one or more<br />spaces. In the listing, the ps command displays the numerical user ID unless the<br />-f flag is used; then the command displays the login name. This flag is<br />equivalent to the -u Ulist flag. See also the u flag.<br /><br />-u Ulist This flag is equivalent to the -U Ulist flag.<br /><br />Options<br /><br />The following options are not preceded by a - (minus sign):<br /><br />a Displays information about all processes with terminals (ordinarily only the<br />user's own processes are displayed).<br /><br />c Displays the command name, as stored internally in the system for purposes of<br />accounting, rather than the command parameters, which are kept in the process<br />address space.<br /><br />e Displays the environment as well as the parameters to the command, up to a<br />limit of 80 characters.<br /><br />ew Wraps display from the e flag one extra line.<br /><br />eww Wraps display from the e flag as many times as necessary.<br /><br />g Displays all processes.<br /><br />l Displays a long listing having the F, S, UID, PID, PPID, C, PRI, NI, ADDR, SZ,<br />PSS, WCHAN, TTY, TIME, and CMD fields.<br /><br />n Displays numerical output. In a long listing, the WCHAN field is printed<br />numerically rather than symbolically. In a user listing, the USER field is<br />replaced by a UID field.<br /><br />s Displays the size (SSIZ) of the kernel stack of each process (for use by<br />system maintainers) in the basic output format. This value is always 0 (zero)<br />for a multi-threaded process.<br /><br />t Tty Displays processes whose controlling tty is the value of the Tty variable,<br />which should be specified as printed by the ps command; that is, 0 for terminal<br />/dev/tty/0, lft0 for /dev/lft0 , and pts/2 for /dev/pts/2.<br /><br />u Displays user-oriented output. This includes the USER, PID, %CPU, %MEM, SZ,<br />RSS, TTY, STAT, STIME, TIME, and COMMAND fields.<br /><br />v Displays the PGIN, SIZE, RSS, LIM, TSIZ, TRS, %CPU, %MEM fields.<br /><br />w Specifies a wide-column format for output (132 columns rather than 80). If<br />repeated, (for example, ww), uses arbitrarily wide output. This information is<br />used to decide how much of long commands to print.<br /><br />x Displays processes with no terminal.<br />&nbsp;</pre><p>Some examples from unix <span class="emphasis">man </span>page.</p><pre class="output">Examples<br /><br />  1. To display all processes, enter:<br /><br />     ps -e -f<br /><br />  2. To list processes owned by specific users, enter:<br /><br />     ps -f -l -ujim,jane,su<br /><br />  3. To list processes that are associated with the /dev/console and /dev/tty1<br />     ttys, enter:<br /><br />     ps -t console,tty/1<br /><br />  4. To list processes not associated with a terminal, enter:<br /><br />     ps -t -<br /><br />  5. To display a specified format with field specifiers, enter:<br /><br />     ps -o ruser,pid,ppid=parent,args<br /><br />     The output is:<br />     RUSER   PID     parent  COMMAND<br /><br />     helene  34      12      ps -o ruser,pid,ppid=parent,args<br /><br />  6. To display a specified format with field descriptors, enter:<br /><br />     ps -o &quot;&lt; %u &gt; %p %y : %a&quot;<br /><br />     The output is:<br />     &lt; RUSER  &gt;      PID     TT :    COMMAND<br /><br />     &lt; helene &gt;      34      pts/3 : ps -o &lt; %u &gt; %p %y : %a<br /><br />  7. To display information about processes and kernel threads controlled by the<br />     current terminal , enter:<br /><br />     ps -lm<br /><br />     The output is similar to:<br />          F S UID  PID PPID  C PRI NI ADDR  SZ WCHAN   TTY  TIME  CMD<br /><br />     240003 A  26 8984 7190  1  60 20 2974 312       pts/1  0:00  -ksh<br /><br />        400 S   -    -    -  1  60  -    -   -           -     -  -<br /><br />     200005 A  26 9256 8984 15  67 20 18ed 164       pts/1  0:00  ps<br /><br />          0 R   -    -    - 15  67  -    -   -           -     -  -<br /><br />  8. To display information about all processes and kernel threads, enter:<br /><br />     ps -emo THREAD<br /><br />     The output is similar to:<br />     USER   PID  PPID  TID S  C PRI SC   WCHAN   FLAG   TTY BND  CMD<br /><br />     jane  1716 19292    - A 10  60  1       * 260801 pts/7   -  biod<br /><br />        -     -     - 4863 S  0  60  0 599e9d8   8400     -   -  -<br /><br />        -     -     - 5537 R 10  60  1 5999e18   2420     -   3  -<br /><br />     luke 19292 18524    - A  0  60  0 586ad84 200001 pts/7   -  -ksh<br /><br />        -     -     - 7617 S  0  60  0 586ad84    400     -   -  -<br /><br />     luke 25864 31168    - A 11  65  0       - 200001 pts/7   -  -<br /><br />        -     -     - 8993 R 11  65  0       -      0     -   -  -<br />&nbsp;</pre><p>&nbsp;</p>]]>
        
    </content>
</entry>

<entry>
    <title>计算数值命令 bc</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/04/shell_command_bc.html" />
    <id>tag:blog.alex.com,2006://1.667</id>

    <published>2006-04-05T10:48:12Z</published>
    <updated>2007-01-12T21:05:15Z</updated>

    <summary>$ echo 2*3 | bc6$ export var1=`echo 2*3|bc`$ echo $var16...</summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="shell" label="Shell" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<pre class="output"><span class="cmd">$ echo 2*3 | bc</span><br />6<br /><br /><span class="cmd">$ export var1=`echo 2*3|bc`<br />$ echo $var1</span><br />6<br /></pre>]]>
        
    </content>
</entry>

<entry>
    <title>get only filename from fullpath</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/03/get_only_filename_from_fullpath.html" />
    <id>tag:blog.alex.com,2006://1.356</id>

    <published>2006-03-03T06:27:50Z</published>
    <updated>2007-01-12T21:38:00Z</updated>

    <summary>$ basename &apos;/tmp/test/abc.sh&apos;abc.sh...</summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="shell" label="Shell" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<pre class="cmd">$ basename '/tmp/test/abc.sh'<br />abc.sh</pre>]]>
        
    </content>
</entry>

<entry>
    <title>du: check files or directories size</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/03/du_check_files_or_directories_size.html" />
    <id>tag:blog.alex.com,2006://1.355</id>

    <published>2006-03-03T06:19:42Z</published>
    <updated>2007-01-12T21:36:19Z</updated>

    <summary><![CDATA[check files or directories size&nbsp;$ du -sk /home/zy87&nbsp;&nbsp; &nbsp;/home/zy-s calculates the total disk usage for all specified files and directories.-k calculates in 1024-byte unites, by default, it will calculate in block count(512-byte in most)$ du -ak /home/zy23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/m152&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/m21&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm/global_brand_prod.bcp4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...]]></summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="shell" label="Shell" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<p>check files or directories size&nbsp;</p><pre class="output">$ du -sk /home/zy<br />87&nbsp;&nbsp; &nbsp;/home/zy</pre><p><br />-s calculates the total disk usage for all specified files and directories.<br /><br />-k calculates in 1024-byte unites, by default, it will calculate in block count(512-byte in most)<br /><br /></p><pre class="output">$ du -ak /home/zy<br />23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/m1<br />52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/m2<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm/global_brand_prod.bcp<br />4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm/crm.ksh<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm/in_files<br />7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm/l_global_brand_prod.sql<br />12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy/crm<br />87&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ../zy</pre><p><br />-a calculates each files and directories specified.<br /><br /><br /></p>]]>
        
    </content>
</entry>

<entry>
    <title>difference in Double quotes and Single quotes</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/02/difference_in_double_quotes_and_single_quotes.html" />
    <id>tag:blog.alex.com,2006://1.61</id>

    <published>2006-02-27T17:03:19Z</published>
    <updated>2007-01-12T21:34:39Z</updated>

    <summary><![CDATA[In unix shell or commands, we often use Double Quotes (&quot;) and Single Quotes ('), but we should understand when we must use Double Quotes or we must use Single Quotes, or we could choose either.Single Quotes ('): Shell will...]]></summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="shell" label="Shell" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<p>In unix shell or commands, we often use Double Quotes (<strong>&quot;</strong>) and Single Quotes (<strong>'</strong>), but we should understand when we must use Double Quotes or we must use Single Quotes, or we could choose either.</p><ul><li>Single Quotes (<strong>'</strong>): Shell will send it to Unix Commands without doing any interpretation.  <br /></li><li>Double Quotes (<strong>&quot;</strong>): Shell will send it to Unix Commands after doing interpretation on following characters</li><ul><li>Doller Signs (<strong>$</strong>)<br /></li><li>Back Quotes (<strong>`</strong>)<br /></li><li>Backslashs (<strong>\</strong>)<br /></li></ul><li>Backslashs (\) is the same as Single Quotes (<strong>'</strong>) to the next character followed this Backslash.</li></ul><p>For understanding the points above, we must understand the 2 different things: Shell and Unix Commands.</p><p>We issue all Unix Commands within Unix Shell environment. Shell will interpret (or say process) strings and variables first before they are sent to Unix Commands. For example: echo, ls are Unix Commands, you will issue these commands in an Unix Shell, like Boune Shell, Kane Shell, etc.</p><p>Practice&nbsp;</p><pre class="output">$ ls<br />file1 file2<br />$ echo file*<br />file1 file2<br />$ echo &quot;file*&quot;<br />file*<br />$ echo $HOME<br />/home/zhangy<br />$ echo &quot;$HOME&quot;<br />/home/zhangy<br />$ echo '$HOME'<br />$HOME</pre><p>Continue to read to see a sample.<br /></p><p>Refer to</p><ul><li><a href="http://bbs.chinaunix.net/viewthread.php?tid=129474&amp;highlight=sed ">http://bbs.chinaunix.net/viewthread.php?tid=129474&amp;highlight=sed&nbsp;</a> </li></ul>]]>
        <![CDATA[<pre class="output"><span class="cmd">/home/zhangdaw/&gt; cat testsed </span><br /><br />inbasket=/ods/sap/in<br />filename=$(echo &quot;${inbasket}&quot; | sed 's/\//\\\//g')&quot;\/ash&quot;<br />echo $filename<br />echo &quot;ashaaa&quot; | sed -e &quot;s/ash/${filename}/g&quot;</pre><pre class="output"><br /><span class="cmd">/home/zhangdaw/&gt; ./testsed</span><br /><br />\/ods\/sap\/in\/ash<br />/ods/sap/in/ashaaa </pre>]]>
    </content>
</entry>

<entry>
    <title>Shell 编程学习笔记(二)</title>
    <link rel="alternate" type="text/html" href="http://www.aiview.com/2006/02/shell_notes_2.html" />
    <id>tag:blog.alex.com,2006://1.49</id>

    <published>2006-02-21T10:39:29Z</published>
    <updated>2009-08-14T12:31:35Z</updated>

    <summary>匹配多个tab 将一个或多个tab符号替换为一个空白。方法1： $ sed &apos;s/\t+/ /g&apos; file 方法2： $ awk &apos;{gsub(/\t+/, &quot; &quot;); print}&apos; test 获取文件最后一行的最后一列，分隔最后一列的空格数量未知。 文件如下，希望获得最后一个数字：3 cat test.dat A.B.C.D.E.A.B.C.D.E A.B.C.D.E.A.B.C.D.E A.B.C.D.E.A.B.C.D.E COUNT 3 方法1： $ tail -1 test.dat | cut -d&apos; &apos; -f2- | tr -d &apos; &apos; 方法2：...</summary>
    <author>
        <name>Alex</name>
        
    </author>
    
        <category term="Unix Shell" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="shell" label="Shell" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="学习笔记" label="学习笔记" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.aiview.com/">
        <![CDATA[<h4>匹配多个tab</h4>
<p>
将一个或多个tab符号替换为一个空白。方法1：
</p>
<pre class="cmd">$ sed 's/\t+/ /g' file
</pre>
<p>方法2：</p>
<pre class="cmd">$ awk '{gsub(/\t+/, " "); print}' test</pre>
<h4>获取文件最后一行的最后一列，分隔最后一列的空格数量未知。</h4>
<p>文件如下，希望获得最后一个数字：3</p>
<pre class="cmd">cat test.dat</pre>
<pre class="output">A.B.C.D.E.A.B.C.D.E
A.B.C.D.E.A.B.C.D.E
A.B.C.D.E.A.B.C.D.E
COUNT       3
</pre>
<p>方法1：</p>
<pre class="cmd">$ tail -1 test.dat | cut -d' ' -f2- | tr -d ' '
</pre>
<p>方法2：</p>
<pre class="cmd">$ awk 'NF&gt;1 {a=$NF}END{print a}' test.dat
</pre>
<h4>Shell的Chr() 函数</h4>
<p>Chr(10进制数)</p>
<pre class="cmd">$ echo 65 | awk '{printf "%c\n", $0}'
A
</pre>
<p>Chr(16进制数)</p>
<pre class="cmd">echo '0x41' | awk '{printf "%c\n", strtonum($0)}'
A
</pre>
<h4>Shell的Asc()函数</h4>
<pre class="cmd">$ echo A | od -td1 | sed -r 's/[\t ]+/ /g' | awk 'NF&gt;1{print $2}'
65
$ echo A | od -tx1 | sed -r 's/[\t ]+/ /g' | awk 'NF&gt;1{print $2}'
41</pre>
<h4>将10进制数转换成16进制数</h4>
<pre class="cmd">$ echo 10 |awk '{printf "%x", $0)}'
a</pre>
<p>希望有前缀0x</p>
<pre class="cmd">$ echo 10 |awk '{printf "%#x", $0}'
0xa</pre>
<p>希望不足2位前面补零</p>
<pre class="cmd">$ echo 10 |awk '{printf "%#.2x", $0}'
0x0a
</pre>
<h4>awk 在正则表达式中引用一个变量</h4>
<p>awk 中，通常我们使用2个slash "/.../" 将正则表达式wrap 起来，比如下面的awk 命令将文件中每一行开头的"str"替换为"newStr"：</p>
<pre class="cmd">
$ awk '{sub(/^str/, "newStr"); print}' file
</pre>
<p>但如果"str" 是一个awk变量或者是一个函数的返回值，那么需要进行如下修改才能工作：将"/.../"替换成双引号，并使变量在双引号之外。如下：</p>
<pre class="cmd">
$ awk '{sub("^"$NF, "newStr"); print}' file
</pre>
<p>或者：</p>
<pre class="cmd">
$ awk '{reg = "^"$NF; sub(reg, "newStr"); print}' file
</pre>
<p>以上$NF是awk的内部变量，代表当前行最后一列的值，可以替换成其它awk 变量或者有返回值的函数。如果需要，变量后面可以继续添加用双引号引起的正则表达式。</p>
]]>
        
    </content>
</entry>

</feed>
