linuxÄں˶ÁÊé±Ê¼Ç£¨½ø³ÌÖÕÖ¹º¯Êý·ÖÎö£©Èý
do_exit() Function
-----------------------------------------------------------------------
kernel/exit.c
707 NORET_TYPE void do_exit(long code)
708 {
709 struct task_struct *tsk = current;
710
711 if (unlikely(in_interrupt()))
712 panic("Aiee, killing interrupt handler!");
713 if (unlikely(!tsk->pid))
714 panic("Attempted to kill the idle task!");
715 if (unlikely(tsk->pid == 1))
716 panic("Attempted to kill init!");
717 if (tsk->io_context)
718 exit_io_context();
719 tsk->flags |= PF_EXITING;
720 del_timer_sync(&tsk->real_timer);
721
722 if (unlikely(in_atomic()))
723 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n",
724 current->comm, current->pid,
725 preempt_count());
-----------------------------------------------------------------------
Line 707²ÎÊýcodeÊǽø³Ç·µ»Ø¸ø¸¸½ø³ÌµÄÍ˳öÂë Lines 711716 È·±£Ä¿Ç°½ø³Ì²»ÊÇÒ»¸öÖжϴ¦Àí½ø³Ì£¬È·±£²»ÊÇidle½ø³Ì£¨PID=0£©»òÕßÊÇinit½ø³Ì£¨PID=1£©£¬init½ø³ÌÖ»ÓÐϵͳ±»ÖÕֹʱ²ÅÄÜÍ˳ö£» Line 719 ½«¸Ã½ø³ÌµÄflagsÓòÉèÖÃΪPF_EXITING£¬Õâ±íÃ÷µ±Ç°½ø³Ì±»ÖÕÖ¹£» -----------------------------------------------------------------------
kernel/exit.c
...
727 profile_exit_task(tsk);
728
729 if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
730 current->ptrace_message = code;
731 ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
732 }
733
734 acct_process(code);
735 __exit_mm(tsk);
736
737 exit_sem(tsk);
738 __exit_files(tsk);
739 __exit_fs(tsk);
740 exit_namespace(tsk);
741 exit_thread();
...
-----------------------------------------------------------------------
Lines 729732 Èç¹û½ø³Ì±»ptraced¶øÇÒPT_TRACE_EXIT ±»ÉèÖã¬ÎÒÃǽ«exit_code×÷ΪÏûϢ֪ͨ¸¸½ø³Ì Lines 735742 ½«½ø³ÌÖв»ÓõÄ×ÊÔ´clean upµô£¬__exit_mm()ÓÃÓÚÊÍ·Å·ÖÅä¸ø½ø³ÌµÄÄڴ棬ºÍÊͷźʹ˽ø³ÌÏà¹ØµÄmm_struct£¬exit_sem()½«´ËÈÎÎñ´ÓIPCÖзÖÀ룬__exit_files() ÊÍ·Å·ÖÅä¸øÈÎÎñµÄÎļþ£¬²¢ÇÒ½«Æä±êʶ·û¼õÈ¥£¬_
Ïà¹ØÎĵµ£º
Linux 2.6Äں˵ÄÒ»¸öÖØÒªÌØÉ«ÊÇÌṩÁËͳһµÄÄÚºËÉ豸ģÐÍ¡£Ëæ׿¼ÊõµÄ²»¶Ï½ø²½£¬ÏµÍ³µÄÍØÆ˽ṹԽÀ´Ô½¸´ÔÓ£¬¶ÔÖÇÄܵçÔ´¹ÜÀí¡¢ÈȲå°ÎÒÔ¼°plug and playµÄÖ§³ÖÒªÇóÒ²Ô½À´Ô½¸ß£¬2.4ÄÚºËÒѾÄÑÒÔÂú×ãÕâЩÐèÇó¡£ÎªÊÊÓ¦ÕâÖÖÐÎÊƵÄÐèÒª£¬2.6Äں˿ª·¢ÁËȫеÄÉ豸ģÐÍ¡£
2.6 ......
include/linux/sched.h
384 struct task_struct {
385 volatile long state;
386 struct thread_info *thread_info;
387 atomic_t usage;
388 unsigned long flags;
389 &nbs ......
1. ÄÚºËѧϰ·½·¨£¬±àÒë¡¢µ÷ÊԵȳ£¼ûÎÊÌâ
1.1 ¹ØÓÚ±àÒëÉý¼¶Äں˵½2.6.0µÄһЩÎÊÌâ ×÷Õߣºommm
http://linux.chinaunix.net/bbs/thread-281831-1-5.html
1.2 VMWare Workstation 6.0µ÷ÊÔLinux Kernel£¬¾¹Èç´Ë·½±ã ×÷Õߣºalbcamus
http://linux.chinaunix.net/bb ......
linux ¿ª»úÆô¶¯½Å±¾Ë³Ðò¡£
µÚÒ»²½£ºÆô¶¯ÄÚºË
µÚ¶þ²½£ºÖ´ÐÐinit £¨ÅäÖÃÎļþ/etc/inittab£©
µÚÈý²½£ºÆô¶¯ÏàÓ¦µÄ½Å±¾£¬²¢ÇÒ´ò¿ªÖÕ¶Ë/etc/init.d
rc.sysinit rc.d(ÀïÃæµÄ½Å±¾£© rc.local
µÚËIJ½£ºÆô¶¯loginµÇ¼½çÃæ login
µÚÎå²½:ÔÚÓû§µÇ¼µÄʱºòÖ´ÐÐsh½Å±¾µÄ˳Ðò£ºÃ¿´ÎµÇ¼µÄʱºò¶ ......