// Per-process state structproc { structspinlocklock;
// p->lock must be held when using these: enumprocstatestate;// Process state structproc *parent;// Parent process void *chan; // If non-zero, sleeping on chan int killed; // If non-zero, have been killed int xstate; // Exit status to be returned to parent's wait int pid; // Process ID
// these are private to the process, so p->lock need not be held. uint64 kstack; // Virtual address of kernel stack uint64 sz; // Size of process memory (bytes) pagetable_t pagetable; // User page table structtrapframe *trapframe;// data page for trampoline.S structcontextcontext;// swtch() here to run process structfile *ofile[NOFILE];// Open files structinode *cwd;// Current directory char name[16]; // Process name (debugging) int mask; // 添加mask值 };
4、添加sys_trace()到kernel/sysproc.c
sys_trace实现:
1 2 3 4 5 6 7 8 9
uint64 sys_trace(void) { int n; if (argint(0, &n) < 0) // 判断参数是否获取成功 return-1; myproc()->mask = n; // 将argv[1]保存到当前进程的mask中 return0; }
5、修改kernel/proc.c中的fork函数,添加子进程复制父进程mask的功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int fork(void) { /* do something .... */ safestrcpy(np->name, p->name, sizeof(p->name)); // 复制 mask np->mask = p->mask;