亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? forkexit.c

?? 一個簡單的操作系統minix的核心代碼
?? C
字號:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				src/mm/forkexit.c	 	 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

16800	/* This file deals with creating processes (via FORK) and deleting them (via
16801	 * EXIT/WAIT).  When a process forks, a new slot in the 'mproc' table is
16802	 * allocated for it, and a copy of the parent's core image is made for the
16803	 * child.  Then the kernel and file system are informed.  A process is removed
16804	 * from the 'mproc' table when two events have occurred: (1) it has exited or
16805	 * been killed by a signal, and (2) the parent has done a WAIT.  If the process
16806	 * exits first, it continues to occupy a slot until the parent does a WAIT.
16807	 *
16808	 * The entry points into this file are:
16809	 *   do_fork:    perform the FORK system call
16810	 *   do_mm_exit: perform the EXIT system call (by calling mm_exit())
16811	 *   mm_exit:    actually do the exiting
16812	 *   do_wait:    perform the WAITPID or WAIT system call
16813	 */
16814	
16815	
16816	#include "mm.h"
16817	#include <sys/wait.h>
16818	#include <minix/callnr.h>
16819	#include <signal.h>
16820	#include "mproc.h"
16821	#include "param.h"
16822	
16823	#define LAST_FEW            2   /* last few slots reserved for superuser */
16824	
16825	PRIVATE pid_t next_pid = INIT_PID+1;    /* next pid to be assigned */
16826	
16827	FORWARD _PROTOTYPE (void cleanup, (register struct mproc *child) );
16828	
16829	/*===========================================================================*
16830	 *                              do_fork                                      *
16831	 *===========================================================================*/
16832	PUBLIC int do_fork()
16833	{
16834	/* The process pointed to by 'mp' has forked.  Create a child process. */
16835	
16836	  register struct mproc *rmp;   /* pointer to parent */
16837	  register struct mproc *rmc;   /* pointer to child */
16838	  int i, child_nr, t;
16839	  phys_clicks prog_clicks, child_base = 0;
16840	  phys_bytes prog_bytes, parent_abs, child_abs; /* Intel only */
16841	
16842	 /* If tables might fill up during FORK, don't even start since recovery half
16843	  * way through is such a nuisance.
16844	  */
16845	  rmp = mp;
16846	  if (procs_in_use == NR_PROCS) return(EAGAIN);
16847	  if (procs_in_use >= NR_PROCS-LAST_FEW && rmp->mp_effuid != 0)return(EAGAIN);
16848	
16849	  /* Determine how much memory to allocate.  Only the data and stack need to
16850	   * be copied, because the text segment is either shared or of zero length.
16851	   */
16852	  prog_clicks = (phys_clicks) rmp->mp_seg[S].mem_len;
16853	  prog_clicks += (rmp->mp_seg[S].mem_vir - rmp->mp_seg[D].mem_vir);
16854	  prog_bytes = (phys_bytes) prog_clicks << CLICK_SHIFT;
16855	  if ( (child_base = alloc_mem(prog_clicks)) == NO_MEM) return(EAGAIN);
16856	
16857	  /* Create a copy of the parent's core image for the child. */
16858	  child_abs = (phys_bytes) child_base << CLICK_SHIFT;
16859	  parent_abs = (phys_bytes) rmp->mp_seg[D].mem_phys << CLICK_SHIFT;
16860	  i = sys_copy(ABS, 0, parent_abs, ABS, 0, child_abs, prog_bytes);
16861	  if (i < 0) panic("do_fork can't copy", i);
16862	
16863	  /* Find a slot in 'mproc' for the child process.  A slot must exist. */
16864	  for (rmc = &mproc[0]; rmc < &mproc[NR_PROCS]; rmc++)
16865	        if ( (rmc->mp_flags & IN_USE) == 0) break;
16866	
16867	  /* Set up the child and its memory map; copy its 'mproc' slot from parent. */
16868	  child_nr = (int)(rmc - mproc);        /* slot number of the child */
16869	  procs_in_use++;
16870	  *rmc = *rmp;                  /* copy parent's process slot to child's */
16871	
16872	  rmc->mp_parent = who;         /* record child's parent */
16873	  rmc->mp_flags &= ~TRACED;     /* child does not inherit trace status */
16874	  /* A separate I&D child keeps the parents text segment.  The data and stack
16875	   * segments must refer to the new copy.
16876	   */
16877	  if (!(rmc->mp_flags & SEPARATE)) rmc->mp_seg[T].mem_phys = child_base;
16878	  rmc->mp_seg[D].mem_phys = child_base;
16879	  rmc->mp_seg[S].mem_phys = rmc->mp_seg[D].mem_phys + 
16880	                        (rmp->mp_seg[S].mem_vir - rmp->mp_seg[D].mem_vir);
16881	  rmc->mp_exitstatus = 0;
16882	  rmc->mp_sigstatus = 0;
16883	
16884	  /* Find a free pid for the child and put it in the table. */
16885	  do {
16886	        t = 0;                  /* 't' = 0 means pid still free */
16887	        next_pid = (next_pid < 30000 ? next_pid + 1 : INIT_PID + 1);
16888	        for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++)
16889	                if (rmp->mp_pid == next_pid || rmp->mp_procgrp == next_pid) {
16890	                        t = 1;
16891	                        break;
16892	                }
16893	        rmc->mp_pid = next_pid; /* assign pid to child */
16894	  } while (t);
16895	
16896	  /* Tell kernel and file system about the (now successful) FORK. */
16897	  sys_fork(who, child_nr, rmc->mp_pid, child_base); /* child_base is 68K only*/
16898	  tell_fs(FORK, who, child_nr, rmc->mp_pid);
16899	
16900	  /* Report child's memory map to kernel. */
16901	  sys_newmap(child_nr, rmc->mp_seg);
16902	
16903	  /* Reply to child to wake it up. */
16904	  reply(child_nr, 0, 0, NIL_PTR);
16905	  return(next_pid);              /* child's pid */
16906	}
	
	
16909	/*===========================================================================*
16910	 *                              do_mm_exit                                   *
16911	 *===========================================================================*/
16912	PUBLIC int do_mm_exit()
16913	{
16914	/* Perform the exit(status) system call. The real work is done by mm_exit(),
16915	 * which is also called when a process is killed by a signal.
16916	 */
16917	
16918	  mm_exit(mp, status);
16919	  dont_reply = TRUE;            /* don't reply to newly terminated process */
16920	  return(OK);                   /* pro forma return code */
16921	}
	
	
16924	/*===========================================================================*
16925	 *                              mm_exit                                      *
16926	 *===========================================================================*/
16927	PUBLIC void mm_exit(rmp, exit_status)
16928	register struct mproc *rmp;     /* pointer to the process to be terminated */
16929	int exit_status;                /* the process' exit status (for parent) */
16930	{
16931	/* A process is done.  Release most of the process' possessions.  If its
16932	 * parent is waiting, release the rest, else hang.
16933	 */
16934	
16935	  register int proc_nr;
16936	  int parent_waiting, right_child;
16937	  pid_t pidarg, procgrp;
16938	  phys_clicks base, size, s;            /* base and size used on 68000 only */
16939	
16940	  proc_nr = (int) (rmp - mproc);        /* get process slot number */
16941	
16942	  /* Remember a session leader's process group. */
16943	  procgrp = (rmp->mp_pid == mp->mp_procgrp) ? mp->mp_procgrp : 0;
16944	
16945	  /* If the exited process has a timer pending, kill it. */
16946	  if (rmp->mp_flags & ALARM_ON) set_alarm(proc_nr, (unsigned) 0);
16947	
16948	  /* Tell the kernel and FS that the process is no longer runnable. */
16949	  tell_fs(EXIT, proc_nr, 0, 0);  /* file system can free the proc slot */
16950	  sys_xit(rmp->mp_parent, proc_nr, &base, &size);
16951	
16952	  /* Release the memory occupied by the child. */
16953	  if (find_share(rmp, rmp->mp_ino, rmp->mp_dev, rmp->mp_ctime) == NULL) {
16954	        /* No other process shares the text segment, so free it. */
16955	        free_mem(rmp->mp_seg[T].mem_phys, rmp->mp_seg[T].mem_len);
16956	  }
16957	  /* Free the data and stack segments. */
16958	  free_mem(rmp->mp_seg[D].mem_phys,
16959	      rmp->mp_seg[S].mem_vir + rmp->mp_seg[S].mem_len - rmp->mp_seg[D].mem_vir);
16960	
16961	  /* The process slot can only be freed if the parent has done a WAIT. */
16962	  rmp->mp_exitstatus = (char) exit_status;
16963	  pidarg = mproc[rmp->mp_parent].mp_wpid;       /* who's being waited for? */
16964	  parent_waiting = mproc[rmp->mp_parent].mp_flags & WAITING;
16965	  if (pidarg == -1 || pidarg == rmp->mp_pid || -pidarg == rmp->mp_procgrp)
16966	        right_child = TRUE;             /* child meets one of the 3 tests */
16967	  else
16968	        right_child = FALSE;            /* child fails all 3 tests */
16969	  if (parent_waiting && right_child)
16970	        cleanup(rmp);                   /* tell parent and release child slot */
16971	  else
16972	        rmp->mp_flags |= HANGING;       /* parent not waiting, suspend child */
16973	
16974	  /* If the process has children, disinherit them.  INIT is the new parent. */
16975	  for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
16976	        if (rmp->mp_flags & IN_USE && rmp->mp_parent == proc_nr) {
16977	                /* 'rmp' now points to a child to be disinherited. */
16978	                rmp->mp_parent = INIT_PROC_NR;
16979	                parent_waiting = mproc[INIT_PROC_NR].mp_flags & WAITING;
16980	                if (parent_waiting && (rmp->mp_flags & HANGING)) cleanup(rmp);
16981	        }
16982	  }
16983	
16984	  /* Send a hangup to the process' process group if it was a session leader. */
16985	  if (procgrp != 0) check_sig(-procgrp, SIGHUP);
16986	}
	
	
16989	/*===========================================================================*
16990	 *                              do_waitpid                                   *
16991	 *===========================================================================*/
16992	PUBLIC int do_waitpid()
16993	{
16994	/* A process wants to wait for a child to terminate. If one is already waiting,
16995	 * go clean it up and let this WAIT call terminate.  Otherwise, really wait.
16996	 * Both WAIT and WAITPID are handled by this code.
16997	 */
16998	
16999	  register struct mproc *rp;
17000	  int pidarg, options, children, res2;
17001	
17002	  /* A process calling WAIT never gets a reply in the usual way via the
17003	   * reply() in the main loop (unless WNOHANG is set or no qualifying child
17004	   * exists).  If a child has already exited, the routine cleanup() sends 
17005	   * the reply to awaken the caller.
17006	   */
17007	
17008	  /* Set internal variables, depending on whether this is WAIT or WAITPID. */
17009	  pidarg  = (mm_call == WAIT ? -1 : pid);       /* first param of waitpid */
17010	  options = (mm_call == WAIT ?  0 : sig_nr);    /* third param of waitpid */
17011	  if (pidarg == 0) pidarg = -mp->mp_procgrp;    /* pidarg < 0 ==> proc grp */
17012	
17013	  /* Is there a child waiting to be collected? At this point, pidarg != 0:
17014	   *    pidarg  >  0 means pidarg is pid of a specific process to wait for
17015	   *    pidarg == -1 means wait for any child
17016	   *    pidarg  < -1 means wait for any child whose process group = -pidarg
17017	   */
17018	  children = 0;
17019	  for (rp = &mproc[0]; rp < &mproc[NR_PROCS]; rp++) {
17020	        if ( (rp->mp_flags & IN_USE) && rp->mp_parent == who) {
17021	                /* The value of pidarg determines which children qualify. */
17022	                if (pidarg  > 0 && pidarg != rp->mp_pid) continue;
17023	                if (pidarg < -1 && -pidarg != rp->mp_procgrp) continue;
17024	
17025	                children++;             /* this child is acceptable */
17026	                if (rp->mp_flags & HANGING) {
17027	                        /* This child meets the pid test and has exited. */
17028	                        cleanup(rp);    /* this child has already exited */
17029	                        dont_reply = TRUE;
17030	                        return(OK);
17031	                }
17032	                if ((rp->mp_flags & STOPPED) && rp->mp_sigstatus) {
17033	                        /* This child meets the pid test and is being traced.*/
17034	                        res2 =  0177 | (rp->mp_sigstatus << 8);
17035	                        reply(who, rp->mp_pid, res2, NIL_PTR);
17036	                        dont_reply = TRUE;
17037	                        rp->mp_sigstatus = 0;
17038	                        return(OK);
17039	                }
17040	        }
17041	  }
17042	
17043	  /* No qualifying child has exited.  Wait for one, unless none exists. */
17044	  if (children > 0) {
17045	        /* At least 1 child meets the pid test exists, but has not exited. */
17046	        if (options & WNOHANG) return(0);    /* parent does not want to wait */
17047	        mp->mp_flags |= WAITING;             /* parent wants to wait */
17048	        mp->mp_wpid = (pid_t) pidarg;        /* save pid for later */
17049	        dont_reply = TRUE;                   /* do not reply now though */
17050	        return(OK);                          /* yes - wait for one to exit */
17051	  } else {
17052	        /* No child even meets the pid test.  Return error immediately. */
17053	        return(ECHILD);                      /* no - parent has no children */
17054	  }
17055	}
	
	
17058	/*===========================================================================*
17059	 *                              cleanup                                      *
17060	 *===========================================================================*/
17061	PRIVATE void cleanup(child)
17062	register struct mproc *child;   /* tells which process is exiting */
17063	{
17064	/* Finish off the exit of a process.  The process has exited or been killed
17065	 * by a signal, and its parent is waiting.
17066	 */
17067	
17068	  int exitstatus;
17069	
17070	  /* Wake up the parent. */
17071	  exitstatus = (child->mp_exitstatus << 8) | (child->mp_sigstatus & 0377);
17072	  reply(child->mp_parent, child->mp_pid, exitstatus, NIL_PTR);
17073	  mproc[child->mp_parent].mp_flags &= ~WAITING; /* parent no longer waiting */
17074	
17075	  /* Release the process table entry. */
17076	  child->mp_flags = 0;
17077	  procs_in_use--;
17078	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲电影视频在线| 欧美性生活影院| 在线观看视频一区二区欧美日韩 | 亚洲第一激情av| 国产一区啦啦啦在线观看| 91久久精品午夜一区二区| 久久午夜国产精品| 日韩福利电影在线| 色婷婷综合久久久久中文一区二区| 精品国产污污免费网站入口 | 欧美在线色视频| 国产精品色一区二区三区| 毛片av一区二区| 欧美精品日韩精品| 一区二区三区av电影| 国产成人欧美日韩在线电影| 欧美一卡在线观看| 日韩中文字幕麻豆| 欧美日韩成人综合天天影院| 伊人夜夜躁av伊人久久| 色哟哟一区二区在线观看| 亚洲国产精品黑人久久久| 国产真实乱子伦精品视频| 欧美一区二区视频在线观看| 日韩高清电影一区| 欧美日韩黄色一区二区| 一区二区三区国产精华| 91麻豆成人久久精品二区三区| 欧美极品美女视频| 国产成人精品1024| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 日本中文在线一区| 91精品国产综合久久精品性色| 午夜精品久久久久久久久久| 欧美性色aⅴ视频一区日韩精品| 一区二区三区中文免费| 色中色一区二区| 亚洲综合在线观看视频| 欧美无人高清视频在线观看| 亚洲电影第三页| 欧美女孩性生活视频| 日本va欧美va瓶| 久久中文娱乐网| 国产成人亚洲综合a∨婷婷| 国产精品久久毛片a| 91精彩视频在线观看| 午夜欧美大尺度福利影院在线看| 欧美一区二区私人影院日本| 国产一区二区网址| 国产精品久久久久久久久免费樱桃 | 日本高清无吗v一区| 午夜免费久久看| 久久亚洲综合av| 99久精品国产| 亚洲亚洲精品在线观看| 日韩三级中文字幕| 成人av网站在线观看免费| 亚洲免费观看高清在线观看| 91精品国产91综合久久蜜臀| 国产在线精品一区二区不卡了| 亚洲天堂av一区| 在线电影一区二区三区| 国产福利一区二区三区视频在线| 亚洲同性同志一二三专区| 欧美高清视频不卡网| 国产1区2区3区精品美女| 一区二区三区四区在线播放| 欧美男同性恋视频网站| 国产成人午夜精品影院观看视频| 亚洲永久精品国产| 久久久久久一二三区| 在线区一区二视频| 精品在线观看免费| 亚洲精品中文字幕在线观看| 精品国产网站在线观看| 色94色欧美sute亚洲线路二| 国产综合久久久久久久久久久久| 亚洲激情欧美激情| 国产日本欧美一区二区| 91精品免费在线观看| 99久久er热在这里只有精品15| 久久国产日韩欧美精品| 一区二区三区毛片| 中文字幕免费观看一区| 日韩天堂在线观看| 在线观看一区二区视频| 不卡的av网站| 国产激情一区二区三区| 另类欧美日韩国产在线| 亚洲成人激情av| 亚洲欧美日韩精品久久久久| 国产午夜久久久久| 日韩精品最新网址| 91麻豆精品国产91久久久久久久久| 91色.com| 成人av电影在线网| 国产高清在线观看免费不卡| 久久99精品久久久久久| 免费在线看成人av| 亚洲电影一级片| 亚洲午夜激情网页| 一区二区三区日韩欧美| 亚洲欧洲日韩av| 中文字幕日韩一区| 中文字幕电影一区| 久久精品人人做人人综合| 欧美tickling网站挠脚心| 91精品婷婷国产综合久久性色| 欧美日韩一区二区三区免费看| 色狠狠综合天天综合综合| 91首页免费视频| 色综合亚洲欧洲| 99热99精品| 色综合久久九月婷婷色综合| 99re66热这里只有精品3直播| 国产成人av一区二区三区在线观看| 韩国av一区二区三区在线观看| 精品一区二区免费视频| 国内成+人亚洲+欧美+综合在线| 久久精品国产一区二区三| 蜜桃av噜噜一区| 国内精品第一页| 国产成人午夜精品5599| 99国产欧美久久久精品| 91免费在线视频观看| 色婷婷av一区二区三区之一色屋| 色婷婷精品久久二区二区蜜臀av | 欧美sm美女调教| 久久精品这里都是精品| 国产精品二区一区二区aⅴ污介绍| 国产精品久久夜| 亚洲国产成人精品视频| 日韩成人午夜电影| 精品一区二区国语对白| 国产成人av一区二区三区在线| gogogo免费视频观看亚洲一| 91黄视频在线| 欧美一区二区在线视频| xfplay精品久久| 亚洲欧美日韩久久精品| 免费在线一区观看| gogo大胆日本视频一区| 欧美精品一二三| 国产色91在线| 亚洲va国产天堂va久久en| 国产专区欧美精品| 91成人在线精品| 精品久久久久久久一区二区蜜臀| 国产精品私人影院| 天天色天天爱天天射综合| 国产一区不卡在线| 在线视频国内自拍亚洲视频| 精品久久久久久久久久久久久久久久久 | 亚洲女人****多毛耸耸8| 日韩电影一二三区| 成人开心网精品视频| 欧美一区二区精美| 国产精品高潮呻吟| 蜜桃91丨九色丨蝌蚪91桃色| 91网站黄www| 久久久亚洲精品一区二区三区 | 日韩欧美国产高清| 一区二区在线看| 国产精品99久久久久久久vr| 欧美日韩日日夜夜| 中文字幕一区二区不卡| 国产在线不卡一卡二卡三卡四卡| 色婷婷av一区二区三区之一色屋| 欧美精品一区二区三区蜜桃| 亚洲福利一区二区| 成人精品电影在线观看| 欧美大片顶级少妇| 午夜影院在线观看欧美| 色综合天天做天天爱| 国产欧美精品一区aⅴ影院 | 久久九九久精品国产免费直播| 亚洲成av人**亚洲成av**| 成人激情图片网| 久久久久久久久99精品| 日韩av电影免费观看高清完整版| 欧美中文字幕一区二区三区亚洲 | 日本成人在线看| 欧美日韩在线亚洲一区蜜芽| 亚洲嫩草精品久久| 成人高清伦理免费影院在线观看| 欧美大白屁股肥臀xxxxxx| 视频一区视频二区中文字幕| 欧美怡红院视频| 一区二区三区免费网站| 91在线丨porny丨国产| 国产精品久久久久久久久晋中 | 国产精品毛片大码女人| 国产成人av福利| 中文字幕av不卡| 国产91精品精华液一区二区三区| 国产午夜久久久久| 国产不卡在线视频| 亚洲国产精华液网站w| 成人精品视频一区二区三区| 国产精品人人做人人爽人人添|