> No Chinese, I hope everyone can accept it!
>
> -
> Love need to learn.
> Love nesed to pay.
> Wade, Coventive, 886-2-8226-3600 EXT 229
>
>
>
>
> ------------------------------------------------- -----------------------
>
> 1. p.15 Chapter 2 - Process Management
> 1. Process Include:
> 1. TEXT Section: Executing Program Code
> 2. Data Section: Global Variables, A Set of Resources
> Such As Open Files, Pending Signals, An Address Space
> 3. One or more Threads of Execution
> 2. Each Thread Includes a Unique Program Counter, Process
> Stack, And Set of Processor Registers, But Linux Does Not
> Differentiate Between Threads and processes.
> 3. Processes Provide Two Vitualization:
> 1. Virtualized PROESSOR: Sharing The Processor Among
> Dozens of Other Processes
> 2. Virtual Memory: It lets the process allocate and
> Manage Memory as if it alone OWNED ALL The Memory in
> The system.
> 4. WHEN a Process EXITS, IT IS Placed Into a Special Zombie
> State That Used To Repesent Terminated Processes Until
> The Parent Calls Wait () or WaitPid ()
> 5. The Kernel Representation of a Running Program as a task,
> And the user-space representation as a process.
> 2. P.16 The Process Descriptor and task structure
> 1. The Kernel Stores The Processes in a Circular Doubly
> Linked List Called The Task List.
> 2. The Process Descriptor Contains The Data That Describe The> Executing Program: Running State, Open Files, The
> Process's Address Space, Pending Signals, Permission,
> Semaphore, Executing Time ...
> 3. THE TASK_STRUCT IS Allocated Via The SLAB Allocator To
> Provide Object Reuse and cache coloring.
> 4. Prior to the 2.6 kernel Series, The Task_struct Was Stored
> At the end of the kernel stack of each process. This
> ALLOWED Architectures with Few Registers, Such as x86, To
> Calculate The Location of The Process Descriptor Via THE
> Stack Pointer WITHOUT USING An Extra Register to Store To
> Location.
> 3. P.18 Storing The Process Descriptor
> 1. The System Identifies Processes by a Unique PID. The
> Default Maximum Value IS 32767 (Up to 4294967296).
> 2. It is very useful to beable to quickly lookup the process
> Descriptor of The Currently Executing Task, Which is Done
> Via the current macro. This Macro Must Be Separately
> Implement by Each Supported Architecture.
> 4. P.19 Process State:
> 1. The State Field of The Process Descriptor Describes The Process Descriptor Describes
> Current Condition of The Process. The value is represented
> By One of FIVE FLAGS:
> 1. Task_running: it is each currently Running OR ON A
> Runqueue Waiting to Run (Runqueue Are Discussed in
> Chap. 3).
> 2. Task_Interruptible: IT IS Sleeping, Blocked, Waiting> For Some Condition To Occur. When this condition
> Occurs, The Kernel Sets The Process's State To
> Task_Running. The Processes Also Awakes Prematurely
> And Becomes Runnable if IT Receives A Signal.
> 3. Task_uninterruptible: IT Will Not Wake Up and Become
> Runnable if IT Receives A Signal. (See fork ())
> 4. Task_zombie: The task Has Terminated, But ITS Parent
> HAS NOT YET ISSUED A WAIT4 () System Call. The Task's
> Process Descriptor Must Remain in Case The Parent
> Wants to Access IT.
> 5. Task_Stopped: This Occurs if The Task Receives
> Sigstop, Sigtstp, Sigttin, Or Sigttou Signal or IF
> IT Receives Any Signal While It Is Being Debugged.
>
> --- Refer ----
>
> 1. Running: ON User Space.
> 2. Interrupt Routine: a Exception Handler Such AS KBD,
> Timer.
> 3. System Call: Such As Read, Write.
> 4. Waiting: Waiting: Wait for an Event.
> 5. Return: Kernel Will Check Scheduler, Signals.
> 6. Ready: Ready to Run.
>
> Interrupt (kernel) Scheduler
> ----------. --------------------------- ---------
.
.
> Running === ==> system call <============================> Waiting> ^. |. ^
> |. | |.
> |. | ===== | => Interrupt Routing <==========
> |.
> |.
> |. V V.
> -----.----- Return <=========================== 中
.
.
>
>
> 5. P.20 Manipulating The Current Process State
> 1. Using the set_task_state (task, state) Function to set the
> Given Task to the given state.
> 6. P.20 Process Context
> 1. One of the Most Important Parts of a Process Is The
> Executing Program Code.
> 2. WHEN a Program Executes a System Call or Triggers AN
> Exception, IT Enters Kernel-Space. At this point, the
> Kernel is said to "be Executing on Behalf of the Process"
> And is in process context.
> 3. WHEN in Process Context, The Current Macro Is Valid.
> 4. All Processes Are Descendents of The Init Process Whose
> PID IS 1.
> 5. Every Process On The System Has Exactly One Parent.
> Likewise, Every Process Can Have One or More Children. The> Relationship Between Processes Is Stored in The Process
> Descriptor.
>
> # pstree
> INIT - - Apache - 5 * [Apache]
> | -Apmd
> | -ATD
> | | -Bash - - Bash - XPRT
> | | | -Logger
> | `-Tee
> | | -BDFLUSH
> | | -BRLTTY
> | -Cron
> | -5 * [Getty]
> | | -Inetd
> | | -Kapmd
> | -Keventd
> | | -Khubd
> | | -Kjournald
> | | KLOGD
> | | -Kreiserfsd
> | -KsoftIRQD_CPU0
> | | -KSwapd
> | | -Kupdated
> `-Syslogd
>
>
> 7. P.22 Process Creation
> 1. fork (): CREATES a Child Process That Is a Copy of The
> Current Task. It diffrom The Parent Only in ITS PID,
> ITS PPID, AND CERTAIN Resources and Statistics, Such AS
> Pending Signals, Which Are Not Inherited.
> 2. EXEC (): Loads a new Executable Into The Address Space and
> Begins Executing IT.
> 3. With Linux, fork () Is Implement Using Copy-On-Write
> Pages. INSTEAD OF Duplicating The Process ADDRESS SPACE,
> The Parent and The Child Can Share A Single Copy. The Data
> Is Marked In Such a Way That IT IS Written To, A
> Duplicate is Made and Each Process Receives a Unique Copy.
> 4. IF exec () IS Called IMMEDIATELY AFTER fork () - They Never
> Need to be copied. The only overhead incotred by fork () IS
> The duplication of the parent's page Tables and the parent's
> CREATION OF A Unique Process Descriptor for the child.> 8. P.23 fork ()
> 1. fork () <- clone () <- do_fork () <- COPY_PROCESS ()
> 1. Calls dup_task_struct () Which Creates A New Kernel
> Stack, thread_info structure, and task_struct for
> The New Process Whose Values Are Identical To Those
> Of the current task.
> 2. CHECK That The New Child Will NOTETED THE
> Resource Limits on The Number of Processes for the Number of Processes for Thane
> Current User.
> 3. Now the child Needs to Differentiate Itself from ITS
> Parent. Various Members of The Process Descriptor
> Area cleand or set to initail value.
> 4. Next, THE Child's State Is Set To
> TASK_UNINTERRUPTIBLE, TO INSURE It Does Not Yet Run.
> 5. Calls Copy_Flags () To update the flags member of the
> Task_struct. The Pf_superPriv Flag, Which Denotes
> WHETHER A Task Used Super-User Priv, IS Cleared. The
> PF_FORKNOEXEC FLAG, Which Denotes a Process That Has
> Not caled exec (), is set.
> 6. Calls get_pid () to assign an available pid to the
> New task.
> 7. Depending on the flags passed to clone (), Either
> Copy or Share Open Files, FileSystem Information,
> Signal Handlers, Process Address Space, And Namespace.
> 8. Share the remaining TimeSlice Between The Parent and
> ITS Child.> 9. Cleanup and return a Pointer to the new child.
> 2. ==> The Kernel Runs The child process first. (Avoid
> Copy-on-Write Overhead)
> 9. P.24 vFork ()
> 1. The vfork () HAS The Same Effect As fork (), Excepter That The
> Page Table Entries of The Parent Process Are Not Copied.
> INSTEAD, THE Child Executes as the sole thread in the
> Parent's Address Space, and The Parent Is Blocked Until
> The child Either calls exec () or exits.
> 2. The child is not allowed to write to the address space.
> 3. ==> Use fork () IS OK in Kernel> 2.2.
> 10. P.25 The Linux Implementation of Threads
> 1. The Linux Kernel Done Not Provide Any Special Scheduling
> Semantics or Data Structures to represent threads.
> INSTEAD, A Thread is Merely a Process Which Share Certain
> Resources. Each Thread Has a Unique Task_struct and
> APPEARS to the KERNEL AS A Normal Process Which Shares The
> Address Space, FileSystem Resources, File Descriptors, And
> INSTALLED SIGNALS.
> 2. Threads Are Created Like Normal Task with The Exception
> That The Clone () System Call is Passed Flags Corresponding
> To specify resources to be shared:
> Clone (Clone_VM | Clone_fs | Clone_Files | Clone_sighand, 0);
> Fork () can be implemented by clone () AS:
> Clone (sigchld, 0);
> VFork () as:
> Clone (Clone_vfork | Clone_VM | SIGCHLD, 0);>
> - Clone () Flags:
>
> Flag meaning
> ================================================== ===================
> Clone_cleartid Clear Tid
> Clone_Detached The Parent Does Not Want A Sigchld Signal Send ON EXIT
> Clone_Files Parent and child Share Open Files
> Clone_fs Parent and Child Share FileSystem Information
> Clone_idletask set pid to zero (only used by the idle tasks)
> Clone_newns Create a New Namespace for the child
> Clone_Parent Child Is To Have Same Parent As ITS Parent
> Clone_Ptrace Continue Tracing CHild
> Clone_Settid Write The Pid Back to User-Space
> Clone_Settls Create a New TLS for the child
> Clone_Sighand Parent and Child Share Signal Handlers
> Clone_sysvsem Parent and child Share System V Sem_undo Semantics
> Clone_thread Parent and child aew in The Same Thread Group
> Clone_vfork vfork () WAS Used and The Parent Will Sleep Until The
> Child Wakes IT
> Clone_VM Parent and Child Share Address Space
> ================================================== ==================================================>
>
> 11. p.26 kernel threads
> 1. kernel threads is offen useful for the kernel to perform
> Some Operations in The Background - Standard Processes
> That EXIST SOLELY IN KERNEL SPACE.
> 2. The Significant Difference Between KERNEL Threads and
> Normal Processes Is That Kernel Threads Do Not Have AN
> Address Space and Do Not Context Switch Into User-Space.
> Kernel threads area schedulable and preemptable as normal
> Processes.
> 3.
>
> # ps axw
> PID TTY Stat Time Command
> 1? S 0:05 init [5]
> 2? SW 0:00 [keventd]
> 0? SWN 0:00 [ksoftirqd_cpu0]
> 0? SW 0:11 [kswapd]
> 0? SW 0:00 [bdflush]
> 0? SW 0:00 [kupdated]
> 7? SW 0:00 [khubd]
> 8? SW 1:45 [kjournald]
> 60? SW 0:00 [Kapmd]
>
>
> 4. Indeed, A Kernel Thread Can Only Be CREATED BY Another
> Kernel thread. The interface for spawning a new kernel
> Thread from an existing one is: int kernel_thread (int
> (* Fn) (void *), void * arg, unsigned long flags) Flags:
> MOST KERNEL THREADS Pass Clone_fs | Clone_Files |
> Clone_sighand
> 12. P.27 Process Termination
> 1. Typically, Processes Destruction Occurs When the Process
> Calls the EXIT () System call: exit () or return from main ().
> 2. a Process Can Also Terminate When IT Receives A Signal OR
> Exception it cannot handle or ignore.
> 3. Do_exit () in kernel Complete a Number of Chores (in
> Kernel / exit.c):
> 1. set the pf_exiting flag in the flags member of the
> Task_struct.
> 2. IF BSD Process Accounting Is Enabled, Call
> Accct_process () to write out accounting information.
> 3. Call __exit__mm () to release the mm_struct held by
.
> 4. Call sem_exit (). Dequeue ITS IPC Semaphor if IT
> Queued Waiting for.
> 5. Call __exit_files (), __EXIT_FS (), EXIT_NAMESPACE (),
> And exit_sighand () to Decrement The usage country of
> Objects Related to File Descriptors, FileSystem
> Data, The Process Namespace, And Signal Handlers,
> Respectively.
> 6. set the task's exit code, stores in the exit_code
> Member of the task_struct, to the code provided by
> EXIT () or wherever kernel mechanism forced the
> Termination.
> 7. Call exit_notify () TO Send Signals to the Task's
> Parent, Reparent Any of The Task's Children To
> Another thread in their thread group or the init> process, and set the task's state to task_zombie.
> 8. Finally, Call Schedule () To Switch To a New Process,
> This is the last code the task will Ever execute.
> 9. ==> The Only Memory It Occupies ITS Kernel Stack
> And Slab Object, Which Contain Its Thread_Info and
> Task_struct structures. The task exissrs solely to
> Provide information to it its parent.
> 13. P.28 Removal of The Process Descriptor
> 1. The ACTS of CLEANING UP AFTER A Process And Removing ITS
> Process Descriptor is Separate.
> 2.hen it is time to finally deallocate the process
> Descriptor, release_task () is invoked. It does the folowing:
> 1. Call Free_UID () To Decrement The Usage Count of The
> Process's User.
> 2. Call unhash_process () to remove the process from the
> Pidhash and remove the process from the task list.
> 3. if the task was ptraaced, reparent it to its Original
> Parent and Remove It from the ptrace list.
> 4. Call Put_Task_struct () To Free The Pages Containing
> The process's kernel stack and thread_info structure
> And deallocate the slab cache containing the
> Task_struct.
> 14. p.28 The Dilemma of the Parentless Task
> 1.
http://www.qnx.com/developers/docs/qnx_4.25_docs/qnx4/sysarch/proc.html
>
> 2. The Solution, Hinted Upon Previously, IS To Reparent A> Task's Children on Exit To Either Another Process in The
> Current Thread Group OR, IF That Fails, The Init Process.
>
> 1. Commands for Process
> Command Description
> PS Report a Snapshot of The Current Processes.
> TOP Display Linux Tasks
> Nice Run a Program with modified scheduling priority
> Renice Alter Priority of Running Processes
> Kill
> Send a Signal To a Process Name Num Action Description
> 0 0 N / A EXIT CODE INDICES IF A Signal May Be Sent
> ALRM 14 EXIT
> HUP 1 EXIT
> INT 2 EXIT
> Kill 9 EXIT this Signal May Not Be Blocked
> PIPE 13 EXIT
> Poll exit
> PROF EXIT
> TERM 15 EXIT
> USR1 EXIT
> USR2 EXIT
> Vtalrm EXIT
> STKFLT EXIT MAY NOT BE IMPLEMENTED
> PWR IGNORE MAY EXIT ON SOME SYSTEMS
> Winch ignore
> Chld ignore
> URG IGNORE
>
> KILLALL KILL Processes by Name
> Skill, Snice Send A Signal or Report Process Status
> PSTree Display a Tree of Processes
> PGREP, PKILL LOOK UP OR SIGNAL Processes Based on Name and
> Other Attributes
> Free Display Amount of Free and Used Memory in the system
> Uptime tell how long The system has been running.
> W show who is logged on and what the isy.
> PIDOF Find The Process ID of a Running Program.
> Fuses or sockets Using Files OR Sockets
> SLEEP, Usleep Delay for a Specified Amount of Time> Time Counting Running Time of A Command
> Jobs Show Stopped Processes List
> History Command History
> NOHUP Run a Command Immune to Hangups, with Output to a non-Tty
> AT, BATCH, ATQ, ATRM Queue, Examine or Delete Jobs for Later
> Execution
> CRONTAB Maintain crontab files for Individual users
> BG, FG Let Stopped Process Run on Background, Foreground
> Procinfo Display System Status Gathered from / Proc
> Reboot, Halt, Shutdown, Poweroff Stop The System
>
> 2. / proc
> 1. APM: Advanced Power Manager
> 1.16 1.2 0x03 0x01 0xFF 0x80 -1% -1?
> 2. Bus: Such PCI, USB BUS.
> 3. Cmdline: Boot Parameter for kernel
> Root = / dev / hda4 VGA = 785 rootfstype = ext3
> 4. CPUInfo
> Attribute Value
> Processor 0
> Vendor_id genuineintel
> CPU Family 6
> Model 7
> Model Name Pentium III (KATMAI)
> Stepping 3
> CPU MHz 451.028
> Cache Size 512 KB
> Fdiv_bug no
> HLT_BUG NO
> F00f_bug no
> Coma_bug no
> FPU YES
> Fpu_exception YES
> CPUID Level 2
> Wp yes
> FLAGS FPU VME DE PSE TSC MSR PAE MCE CX8 SEP MTRR PGE MCA
> Cmov Pat PSE36 MMX FXSR SSE
> BOGOMIPS 897.84
>
> 5. Devices
> * CHARACTER DEVICES:
> Major Number Device Name> 1 MEM
> 2 pty
> 3 TTYP
> 4 TTYS
> 5 CUA
> 7 VCS
> 10 MISC
> 14 Sound
> 29 FB
> 81 Video_Capture
> 108 PPP
> 128 PTM
> 136 PTS
> 162 RAW
> 180 USB
>
> * Block Devices:
> Major Number Device Name
> 2 fd
> 3 IDE0
> 7 loop
> 114 Ataraid
>
> 6. DMA
> 7. Driver
> 8. EXECDOMAINSS
> 9. FB
> 10. FileSystems
> / Dev node? FileSystem
> Nodev rootfs
> Nodev BDEV
> Nodev Proc
> Nodev Sockfs
> Nodev TMPFS
> Nodev SHM
> Nodev PIPEFS
> EXT3
> EXT2
> Nodev Ramfs
> ISO9660
> Nodev Devpts
> Nodev USBDEVFS
> Nodev USBFS
> Nodev Autofs
> Nodev NFS
> Vfat
> Reiserfs
>
> 11. fs
> 12.Ide
> 13.Interrupts
> IRQ Number In CPU0 ??? Name
> 0 20684227 XT-Pic Timer
> 1 74567 XT-Pic Keyboard
> 2 0 XT-Pic Cascade
> 4 153184 XT-PIC Serial> 8 4 XT-PIC RTC
> 10 0 XT-PIC USB-UHCI, ESS SOLO1
> 11 4078280 XT-Pic Eth0
> 12 301378 XT-PIC PS / 2 mouse
> 14 1182857 XT-PIC IDE0
> NMI 0
> Err 0
>
> 14. omem
> Address Description
> 00000000-0009FBFF System RAM
> 0009FC00-0009fff Reserved
> 000A0000-000Bffffff Video Ram Area
> 000c0000-000c7fff video rom
> 000f0000-000fffff System ROM
> 00100000-07FFCFFF System RAM
> 00100000-00245388 kernel code
> 00245389-002D0C03 Kernel Data
> 07FFD000-07ffefff ACPI TABLES
> 07FFF000-07FFFFF ACPI NON-VOLATILE STORAGE
> E1000000-E100007F 3COM Corporation 3C905B 100BaseTX
> [Cyclone]
> E1800000-E3DFFFF PCI BUS # 01
> 1800000-E1800FFF ATI TECHNOLOGIES INC 3D Rage Pro AGP 1x / 2X
> 2000000-E2FFFFFFFF ATI TECHNOLOGIES INC 3D Rage Pro AGP 1x / 2X
> 2000000-E212BFFF VESAFB
> E3f00000-E3FFFFF PCI Bus # 01
> E4000000-E7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEL
> Host Bridge
> FFFF0000-fffffff Reserved
>
> 15. IOPORTS
> IO-Address Description
> 0000-001F DMA1
> 0020-003F PIC1
> 0040-005F Timer
> 0060-006F Keyboard
> 0070-007F RTC
> 0080-008F DMA Page Reg
> 00A0-00BF PIC2> 00c0-00df DMA2
> 00F0-00FF FPU
> 01f0-01f7 IDE0
> 02F8-02FF Serial (SET)
> 03C0-03DF VESAFB
> 03f6-03f6 IDE0
> 03F8-03FF Serial (SET)
> 0CF8-0CFF PCI CONF1
> 9400-947f 3com corporation 3C905B 100BaseTX [cyclone]
> 9400-947f 00: 0C.0
> 9800-9803 ESS Technology ES1969 SOLO-1 Audiodrive
> 9800-9803 ESS SOLO1
> A000-A003 ESS Technology ES1969 SOLO-1 Audiodrive
> 000-A003 Ess Solo1
> A400-A40F ESS Technology ES1969 SOLO-1 Audiodrive
> 400-a40f Ess Solo1
> A800-A80F ESS Technology ES1969 SOLO-1 Audiodrive
> 804-a80f Ess Solo1
> B000-B03F ESS Technology ES1969 SOLO-1 Audiodrive
> 000-b00f Ess Solo1
> B400-B41F Intel Corp. 82371Ab / EB / MB PIIX4 USB
> 400-b41f USB-UHCI
> B800-B80F Intel Corp. 82371Ab / EB / MB PIIX4 IDE
> 800-b807 IDE0
> 808-b80f IDE1
> D000-dfff pci bus # 01
> 800-d8ff ATI TECHNOLOGIES INC 3D Rage Pro AGP 1X / 2X
> E400-E43F Intel Corp. 82371Ab / EB / MB PIIX4 ACPI
> E800-E81F Intel Corp. 82371Ab / EB / MB PIIX4 ACPI
>
> 16. IRQ
> 17. kcore
> 18. kmsg
> 19. ksyms: refer to system.map after building kernel Source
> 20. Loadavg: Refer to "uptime" Command
> 21. LOCKS
> 22. Meminfo: Refer to "free", "TOP" Command> 23. Misc
> 24. Modules: Modules in Kernel: Build In Insmod
> 25. Mounts: Refer to "Mount", Normally LN -S / Proc / Mounts
> / Etc / mtab
> 26. mtrr
> 27. Net
> 28. Partitions: Refer to "fdisk -l"
> Major Minor #Blocks Name
> 3 0 19551168 HDA
> 3 1 4192933 HDA1
> 3 2 88357 HDA2
> 3 3 249007 HDA3
> 3 4 15020775 HDA4
>
> 29. PCI
> 30. SCSI
> 31. Self: "Self" Process, Symbolic to / Proc / # PID
> 32. SLABINFO
> 33. Stat: CPU, SWAP, Interrupt, Diskio, Boot Time
> 34. SWAPS:
>
> FileName Type Size Used Priority
> / dev / hda3 partition 248996 26540 -1
>
>
> 35. SYS
> 36. Sysvipc: IPC
> 37. TTY
> 38. Uptime
> 39. Version: Refer to "uname -a" Command
> 40. Video
>