Difference between revisions of "Process"

From Hackepedia
Jump to navigationJump to search
m
(→‎Debugging a process that's running: process context lifetime)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=119 punk ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=218 free qwest ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=349 cheap vicodin]] [[http://wc1.worldcrossing.com/WebX/.1de609fe qwest ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=225 kyocera ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=174 order cyclobenzaprine]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=186 jazz ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=171 clomid online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=144 cheap xanax]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=236 free tracfone ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=180 online flexeril]] [[http://wc1.worldcrossing.com/WebX/.1de609f3 midi ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a2c ultram]] [[http://wc1.worldcrossing.com/WebX/.1de60a34 free sony ericsson ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a0d free wwe ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=207 real ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=110 free nokia ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=220 punk ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=203 free funny ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=173 free cool ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de609eb free funny ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=83 didrex online]] [[http://wc1.worldcrossing.com/WebX/.1de60a21 paxil online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=172 lorazepam online]] [[http://wc1.worldcrossing.com/WebX/.1de60a1a mtv ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=71 alprazolam online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=190 pharmacy online online]] [[http://wc1.worldcrossing.com/WebX/.1de60a03 sony ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=201 free free ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a0b cheap vigrx]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 free polyphonic ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=358 mp3 ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a23 free polyphonic ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=213 polyphonic ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=150 tramadol online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=163 cheap adipex]] [[http://wc1.worldcrossing.com/WebX/.1de60a2b but ultracet]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=219 viagra online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=82 buy diazepam]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=185 cheap zoloft]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=192 cheap vigrx]] [[http://wc1.worldcrossing.com/WebX/.1de60a1f cheap lisinopril]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=114 pharmacy online online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=75 cheap celexa]] [[http://wc1.worldcrossing.com/WebX/.1de60a05 free sprint ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de609e4 cheap clonazepam]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=353 levitra online]] [[http://wc1.worldcrossing.com/WebX/.1de60a27 but sildenafil]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=140 vicodin online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=337 online xanax]] [[http://wc1.worldcrossing.com/WebX/.1de60a2d cheap valium]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=206 cheap pharmacy online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=126 sildenafil online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=174 cheap wellbutrin]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=160 adipex online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=221 cheap vicodin]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=143 wwe ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=70 free alltel ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=230 free verizon ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=102 midi ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=118 prozac online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=189 cheap lipitor]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=218 sony ericsson ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=232 sony ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=161 cheap albuterol]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=161 cheap viagra]] [[http://wc1.worldcrossing.com/WebX/.1de609e1 carisoprodol online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=128 sony ericsson ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a24 cheap propecia]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=200 nexium]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 cheap lorazepam]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=197 cheap flexeril]] [[http://wc1.worldcrossing.com/WebX/.1de60a07 free tracfone ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=182 clomid online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 paxil online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=208 motorola ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=216 zyban online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=120 free qwest ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=109 free nextel ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=79 clonazepam online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=211 free music ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=226 cheap tramadol]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=333 cheap soma]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=81 buy cyclobenzaprine]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=332 tramadol online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=160 buy ativan]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=68 buy adipex]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=108 cheap nexium]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=167 clonazepam online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=90 cheap hgh]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=132 tenuate online]] [[http://wc1.worldcrossing.com/WebX/.1de60a32 zoloft]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=223 free midi ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=166 order alprazolam]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=72 ambien online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=241 free sony ericsson ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=184 lisinopril online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=194 midi ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=74 carisoprodol online]] [[http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=182 free funny ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=176 didrex online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=196 buy hgh]] [[http://wc1.worldcrossing.com/WebX/.1de60a10 cheap didrex]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=129 sony ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=339 ultram online]] [[http://wc1.worldcrossing.com/WebX/.1de609ec hgh online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=85 free ericsson ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=156 online fioricet]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 cialis]] [[http://wc1.worldcrossing.com/WebX/.1de60a1e flexeril online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=336 carisoprodol online]] [[http://wc1.worldcrossing.com/WebX/.1de609ff real ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=198 cheap hoodia]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=165 cheap ambien]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=186 lipitor online]] [[http://wc1.worldcrossing.com/WebX/.1de609fa online pharmacy]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free free ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=146 zanaflex online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=153 phentermine online]] [[http://wc1.worldcrossing.com/WebX/.1de60a11 diethylpropion online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=240 soma online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=210 free sprint ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de609e7 cheap diazepam]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=125 free sharp ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=170 hydrocodone online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=347 adipex online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=155 buy xanax]] [[http://wc1.worldcrossing.com/WebX/.1de609e3 cheap clomid]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=356 free tracfone ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=222 sharp ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=98 lisinopril online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=223 wellbutrin online]] [[http://wc1.worldcrossing.com/WebX/.1de60a15 free kyocera ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=362 motorola ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 phentermine online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=215 zoloft online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=167 cheap carisoprodol]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=164 alprazolam online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=177 diethylpropion online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=200 nokia ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=69 albuterol online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=357 funny ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=334 order valium]] [[http://wc1.worldcrossing.com/WebX/.1de60a29 tramadol online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=338 fioricet online]] [[http://wc1.worldcrossing.com/WebX/.1de60a09 cheap viagra]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 free samsung ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=198 mtv ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=164 norco online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=199 free music ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=166 buy ativan]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=188 cheap tenuate]] [[http://wc1.worldcrossing.com/WebX/.1de60a17 lipitor online]] [[http://wc1.worldcrossing.com/WebX/.1de60a12 ericsson ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=151 soma online]] [[http://wc1.worldcrossing.com/WebX/.1de609df ambien online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=231 rivotril online]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=343 cialis online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=134 tramadol online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=227 free ericsson ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=228 mtv ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=177 propecia online]] [[http://wc1.worldcrossing.com/WebX/.1de60a14 jazz ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=187 kyocera ringtones]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=345 cheap viagra]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=348 norco]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 free alltel ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=193 buy zanaflex]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=196 free motorola ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 cheap viagra]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=191 cheap lortab]] [[http://wc1.worldcrossing.com/WebX/.1de60a1b music ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a19 mp3 ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de609dc buy albuterol]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=351 clonazepam online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=171 ambien online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=173 xenical online]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=121 free real ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a20 cheap nexium]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=142 wellbutrin]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=130 sonyericsson ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a0e cheap celexa]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=158 diazepam online]] [[http://wc1.worldcrossing.com/WebX/.1de609f7 nextel ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a28 soma online]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=197 mp3 ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=184 hoodia]] [[http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=359 free nextel ringtones]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=165 vicodin online]] [[http://wc1.worldcrossing.com/WebX/.1de60a01 sagem ringtones]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=217 punk ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=117 order propecia]] [[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 mono ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=116 free polyphonic ringtones]] [[http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=96 cheap levitra]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=224 wwe ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de609f0 lorazepam online]] [[http://news.engin.brown.edu/forums/thread-view.asp?tid=209 samsung ringtones]] [[http://wc1.worldcrossing.com/WebX/.1de60a31 zanaflex online]] A process is a program running in a UNIX system.  It communicates with the rest of the system or network by means of [[syscall]]s, [[descriptors]] or [[shared memory]].  A process is in [[protected memory]] also called [[virtual memory]] because address locations are translated by the [[kernel]] from the real physical addresses.  A process cannot read the memory of another process owned by another user unless both processes share that memory which needs to be set up by both.  Interfaces for reading the memory of another process of the same [[uid]] are [[ptrace]] and the /proc [[filesystem]].   
+
== Description of a process ==
 +
 
 +
A process is a program running in a UNIX system.  It communicates with the rest of the system or network by means of [[syscall]]s, [[descriptors]] or [[shared memory]].  A process is in [[protected memory]] also called [[virtual memory]] because address locations are translated by the [[kernel]] from the real physical addresses.  A process cannot read the memory of another process owned by another user unless both processes share that memory which needs to be set up by both.  Interfaces for reading the memory of another process of the same [[uid]] are [[ptrace]] and the /proc [[filesystem]].   
  
 
A process is created by the [[fork]] [[syscall]] by a parent process.  The new process is also called the child.  After fork the child retains all memory and [[descriptors]] of its parent.
 
A process is created by the [[fork]] [[syscall]] by a parent process.  The new process is also called the child.  After fork the child retains all memory and [[descriptors]] of its parent.
Line 20: Line 22:
  
 
   
 
   
=== Ending a Process ===
+
== Ending a Process ==
  
 
A user can end a process by killing it. By default the TERM (15) signal is sent.  It is wise to send a TERM signal to a process so that it can trap this signal and do possible safe shutdown's of open files or databases.  When it is absolutely necessary to immediately kill a process the KILL (9) signal is used, the process terminates immediately without being able to safely shut anything off.  Sometimes a process is "in-disk" (state D in a ps listing) meaning it is awaiting i/o from the kernel.  In this state a process cannot be killed at all and it may be wedged forever until the next boot of the system.
 
A user can end a process by killing it. By default the TERM (15) signal is sent.  It is wise to send a TERM signal to a process so that it can trap this signal and do possible safe shutdown's of open files or databases.  When it is absolutely necessary to immediately kill a process the KILL (9) signal is used, the process terminates immediately without being able to safely shut anything off.  Sometimes a process is "in-disk" (state D in a ps listing) meaning it is awaiting i/o from the kernel.  In this state a process cannot be killed at all and it may be wedged forever until the next boot of the system.
Line 28: Line 30:
 
  $ pkill [[Variables|process]]
 
  $ pkill [[Variables|process]]
  
You will have to have proper [[permission]] to kill this process. You can optionally include a [[signal]] with pkill.
+
You will have to have proper [[permissions|permission]] to kill this process. You can optionally include a [[signal]] with pkill.
  
 
The traditional command to do this is kill(1), which takes the [[pid]] as an argument and optionally the [[signal]] which is supposed to be sent to the process.   
 
The traditional command to do this is kill(1), which takes the [[pid]] as an argument and optionally the [[signal]] which is supposed to be sent to the process.   
Line 38: Line 40:
 
Here is a list of [[signal]]s.
 
Here is a list of [[signal]]s.
  
=== Tracing a Process in BSD ===
+
== Tracing a Process in BSD ==
  
[[BSD]] has the [[ktrace]] command.  With it a processes [[syscall]]s can be traced.  By default ktrace writes the file "ktrace.out".  To switch off tracing a simple "ktrace -C" is used.  To view the contents of the tracefile you would use [[kdump]].  When you need to trace the child of a process the "-i" flag to ktrace is probably best.
+
[[BSD]] has the [[ktrace]] command.  With it a processes [[syscall]]s can be traced.  By default ktrace writes the file "ktrace.out".  To switch off tracing a simple "ktrace -C" is used.  To view the contents of the tracefile you would use [[ktrace|kdump]].  When you need to trace the child of a process the "-i" flag to ktrace is probably best.
  
 
  12926 ls      CALL  stat(0x469b6170,0x7f7fffff7490)
 
  12926 ls      CALL  stat(0x469b6170,0x7f7fffff7490)
Line 69: Line 71:
 
  ...
 
  ...
  
 +
== Tracing a process with strace (Redhat EL9) ==
 +
 +
strace comes with Redhat Enterprise Linux 9 (3) at least on my vserver system.
 +
 +
[pjp@proteus pjp]$ strace -fo trace.out fire
 +
pbug, fire started.
 +
Process 11552 attached
 +
 +
This dumps all information into the file trace.out...
 +
 +
[pjp@proteus pjp]$ head trace.out
 +
11551 execve("/home/pjp/bin/fire",  ["fire"], [/* 26 vars */]) = 0
 +
11551 uname({sys="Linux", node="proteus.solarscale.de", ...}) = 0
 +
11551 brk(0)                            = 0x804c000
 +
11551 old_mmap(NULL, 4096,  PROT_READ|PROT_WRITE,  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fed000
 +
11551 open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
 +
11551 open("/etc/ld.so.cache", O_RDONLY) = 3
 +
11551 fstat64(3, {st_mode=S_IFREG|0644, st_size=20916, ...}) = 0
 +
11551 old_mmap(NULL, 20916, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fe7000
 +
11551 close(3)                          = 0
 +
 +
A bunch of files are opened here in the preload (dynamic linker) of system libraries, there is a lot more after the dynamic libraries are loaded.
  
=== Debugging a process that's running ===
+
== Debugging a process that's running ==
  
 
[[gdb]] allows one to attach to a process.  The process should be compiled with debugging symbols (-g flag).  The debugger attaches to the process like so:
 
[[gdb]] allows one to attach to a process.  The process should be compiled with debugging symbols (-g flag).  The debugger attaches to the process like so:
Line 77: Line 101:
  
 
Where program is the program that's running (ie. /bin/ls) and 1234 is the [[pid]] of the process.  As soon as you attach the processes execution stops and isn't resumed until you quit, step through or continue (after perhaps setting a few breakpoints).
 
Where program is the program that's running (ie. /bin/ls) and 1234 is the [[pid]] of the process.  As soon as you attach the processes execution stops and isn't resumed until you quit, step through or continue (after perhaps setting a few breakpoints).
 +
 +
== A process context lifetime? ==
 +
 +
In a [[UBO]] a process doesn't RUN for very long.  Since UNIX is a multitasking system, other processes are given the chance to run too.  Usually there is a timeout how long a process can run in [[userland]] mode before being context switched.  Another way a context switch occurs if a process calls a [[system call]].

Latest revision as of 09:24, 28 March 2013

Description of a process

A process is a program running in a UNIX system. It communicates with the rest of the system or network by means of syscalls, descriptors or shared memory. A process is in protected memory also called virtual memory because address locations are translated by the kernel from the real physical addresses. A process cannot read the memory of another process owned by another user unless both processes share that memory which needs to be set up by both. Interfaces for reading the memory of another process of the same uid are ptrace and the /proc filesystem.

A process is created by the fork syscall by a parent process. The new process is also called the child. After fork the child retains all memory and descriptors of its parent.

A typical process is composed of text, initialized data, uninitialized data (bss), heap and stack. Because of paging a process' text does not need to be loaded completely into memory but is loaded in chunks called pages when it tries to access an area that hasn't been paged in yet (this causes a page fault to indicate to the kernel that more data is needed). This is called demand paging. When memory pages aren't being used they can be paged out to swap to make room for more memory that other processes may require. When a threshold is reached and processes aren't active for longer periods of time they can be entirely swapped out to disk. This is rather slow and often avoided when possible. Processes can be signal'ed to stop execution, continue execution and to exit including leaving a core file for later analysis.

Each process has a unique pid to identify it and a ppid to identify its parent. Other properties about a process are explained in struct proc in /usr/include/sys/proc.h.


To show all processes in BSD type:

$ ps -auwx

To show all processes in SYSV type:

$ ps -ef

When a process dies it will not be cleaned up completely by the kernel but be set into a zombie state, the parent pid will be signaled with a SIGCHLD signal and it is expected to wait(2) on the zombie child. As soon as this is complete the kernel will clean the process table completely from the zombie process. Orphaned processes that become zombies are waited on by init.


Ending a Process

A user can end a process by killing it. By default the TERM (15) signal is sent. It is wise to send a TERM signal to a process so that it can trap this signal and do possible safe shutdown's of open files or databases. When it is absolutely necessary to immediately kill a process the KILL (9) signal is used, the process terminates immediately without being able to safely shut anything off. Sometimes a process is "in-disk" (state D in a ps listing) meaning it is awaiting i/o from the kernel. In this state a process cannot be killed at all and it may be wedged forever until the next boot of the system.

The latest way to do this is with the pkill command:

$ pkill process

You will have to have proper permission to kill this process. You can optionally include a signal with pkill.

The traditional command to do this is kill(1), which takes the pid as an argument and optionally the signal which is supposed to be sent to the process.

$ kill 324
$ kill -TERM 324
$ kill -KILL 324

Here is a list of signals.

Tracing a Process in BSD

BSD has the ktrace command. With it a processes syscalls can be traced. By default ktrace writes the file "ktrace.out". To switch off tracing a simple "ktrace -C" is used. To view the contents of the tracefile you would use kdump. When you need to trace the child of a process the "-i" flag to ktrace is probably best.

12926 ls       CALL  stat(0x469b6170,0x7f7fffff7490)
12926 ls       NAMI  "."
12926 ls       RET   stat 0
12926 ls       CALL  open(0x528916,0,0)
12926 ls       NAMI  "."
12926 ls       RET   open 3
12926 ls       CALL  fchdir(0x3)
12926 ls       RET   fchdir 0
12926 ls       CALL  open(0x528916,0,0)
12926 ls       NAMI  "."
12926 ls       RET   open 4
12926 ls       CALL  open(0x423e5000,0x4,0)
12926 ls       NAMI  "."
12926 ls       RET   open 6
12926 ls       CALL  fstat(0x6,0x7f7fffff7440)
12926 ls       RET   fstat 0

Above is a snippet of a traced ls.

It is possible to see what processes are traced with the fstat command where a "tr" flag is displayed with the inode of the trace file.

$ fstat | grep mplayer
...
pbug     mplayer    11555   wd /usr     8016513 drwx------   r     8192
pbug     mplayer    11555   tr /usr     8016941 -rw-------  rw  1273886
...

Tracing a process with strace (Redhat EL9)

strace comes with Redhat Enterprise Linux 9 (3) at least on my vserver system.

[pjp@proteus pjp]$ strace -fo trace.out fire
pbug, fire started.
Process 11552 attached

This dumps all information into the file trace.out...

[pjp@proteus pjp]$ head trace.out
11551 execve("/home/pjp/bin/fire",  ["fire"], [/* 26 vars */]) = 0
11551 uname({sys="Linux", node="proteus.solarscale.de", ...}) = 0
11551 brk(0)                            = 0x804c000
11551 old_mmap(NULL, 4096,  PROT_READ|PROT_WRITE,  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fed000
11551 open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
11551 open("/etc/ld.so.cache", O_RDONLY) = 3
11551 fstat64(3, {st_mode=S_IFREG|0644, st_size=20916, ...}) = 0
11551 old_mmap(NULL, 20916, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fe7000
11551 close(3)                          = 0

A bunch of files are opened here in the preload (dynamic linker) of system libraries, there is a lot more after the dynamic libraries are loaded.

Debugging a process that's running

gdb allows one to attach to a process. The process should be compiled with debugging symbols (-g flag). The debugger attaches to the process like so:

$ gdb program 1234

Where program is the program that's running (ie. /bin/ls) and 1234 is the pid of the process. As soon as you attach the processes execution stops and isn't resumed until you quit, step through or continue (after perhaps setting a few breakpoints).

A process context lifetime?

In a UBO a process doesn't RUN for very long. Since UNIX is a multitasking system, other processes are given the chance to run too. Usually there is a timeout how long a process can run in userland mode before being context switched. Another way a context switch occurs if a process calls a system call.