Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarea 1 #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ UPROGS=\
_usertests\
_wc\
_zombie\
_cuenta\

fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
Expand Down Expand Up @@ -250,6 +251,7 @@ qemu-nox-gdb: fs.img xv6.img .gdbinit
EXTRA=\
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
cuenta.c\
printf.c umalloc.c\
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\
Expand Down
9 changes: 9 additions & 0 deletions cuenta.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

int main(void) {
printf(1 , "La cantidad de procesos en ejecucion en la CPU es %d\n", getprocs());
exit();
}
1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void userinit(void);
int wait(void);
void wakeup(void*);
void yield(void);
int countproc(void);

// swtch.S
void swtch(struct context**, struct context*);
Expand Down
18 changes: 18 additions & 0 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,21 @@ procdump(void)
cprintf("\n");
}
}

int
countproc(void)
{
struct proc *p;
int counter = 0;
acquire(&ptable.lock);

for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->state != UNUSED){
counter++;
}
}

release(&ptable.lock);

return counter;
}
3 changes: 3 additions & 0 deletions syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
extern int sys_uptime(void);
extern int sys_getprocs(void);

static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
Expand All @@ -126,6 +127,7 @@ static int (*syscalls[])(void) = {
[SYS_link] sys_link,
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
[SYS_getprocs] sys_getprocs,
};

void
Expand All @@ -143,3 +145,4 @@ syscall(void)
curproc->tf->eax = -1;
}
}

1 change: 1 addition & 0 deletions syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
#define SYS_link 19
#define SYS_mkdir 20
#define SYS_close 21
#define SYS_getprocs 22
7 changes: 7 additions & 0 deletions sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ sys_getpid(void)
return myproc()->pid;
}

int
sys_getprocs(void)
{
return countproc();
}

int
sys_sbrk(void)
{
Expand Down Expand Up @@ -89,3 +95,4 @@ sys_uptime(void)
release(&tickslock);
return xticks;
}

1 change: 1 addition & 0 deletions user.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int getpid(void);
char* sbrk(int);
int sleep(int);
int uptime(void);
int getprocs(void);

// ulib.c
int stat(const char*, struct stat*);
Expand Down
1 change: 1 addition & 0 deletions usys.S
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
SYSCALL(uptime)
SYSCALL(getprocs)