Commit e56c6048 authored by Amir Hosein Kashani's avatar Amir Hosein Kashani

2.1

parent 30dd6b34
...@@ -7,13 +7,29 @@ ...@@ -7,13 +7,29 @@
#include "mmu.h" #include "mmu.h"
#include "proc.h" #include "proc.h"
int table[1200][256] ={0};
int
sys_getpid(void)
{
return myproc()->pid;
}
int int
sys_fork(void) sys_fork(void)
{ {
int dadPid = pid; int dadPid = sys_getpid();
int pidChild = fork(); int pidChild = fork();
//cprintf("father : %d child : %d",dadPid , pidChild);
return for(int i =0;i<256;i++){
if(table[dadPid][i]==0){
table[dadPid][i]=pidChild;
break;
}
}
return pidChild;
} }
int int
...@@ -39,11 +55,7 @@ sys_kill(void) ...@@ -39,11 +55,7 @@ sys_kill(void)
return kill(pid); return kill(pid);
} }
int
sys_getpid(void)
{
return myproc()->pid;
}
int int
sys_sbrk(void) sys_sbrk(void)
...@@ -95,9 +107,21 @@ sys_uptime(void) ...@@ -95,9 +107,21 @@ sys_uptime(void)
//my implimentation //my implimentation
int int
sys_getChildren(void) sys_getChildren(int prosecId)
{ {
return 120; int result=0;
argint(0,&prosecId);
int j=0;
while(table[prosecId][j]!=0){
int temp = table[prosecId][j];
while(temp>0){
temp/=10;
result*=10;
}
result+=table[prosecId][j];
j++;
}
return result;
} }
......
...@@ -3,8 +3,16 @@ ...@@ -3,8 +3,16 @@
#include "user.h" #include "user.h"
int int
main(void) main(int argc,char **argv)
{ {
int a= fork();
fork();
fork();
wait();
wait();
wait();
int b = getChildren(a);
printf(1,"***** %d ********\n",b);
printf(1, "My first xv6 program\n"); printf(1, "My first xv6 program\n");
exit(); exit();
} }
...@@ -23,9 +23,7 @@ int getpid(void); ...@@ -23,9 +23,7 @@ int getpid(void);
char* sbrk(int); char* sbrk(int);
int sleep(int); int sleep(int);
int uptime(void); int uptime(void);
int getChildren(void); int getChildren(int);
// ulib.c // ulib.c
int stat(const char*, struct stat*); int stat(const char*, struct stat*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment