Skip to content
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
1 change: 1 addition & 0 deletions xv6-public/Makefile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ UPROGS=\
_usertests\
_wc\
_zombie\
_getpcount\

fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
Expand Down
11 changes: 11 additions & 0 deletions xv6-public/getpcount.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "types.h"
#include "stat.h"
#include "user.h"

int
main(void){
int running_count;
running_count = getpcount();
printf(1, "Processes currently running: %d\n", running_count);
exit();
}
2 changes: 2 additions & 0 deletions xv6-public/syscall.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
extern int sys_uptime(void);
extern int sys_getpcount(void);

static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
Expand All @@ -121,6 +122,7 @@ static int (*syscalls[])(void) = {
[SYS_link] sys_link,
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
[SYS_getpcount] sys_getpcount,
};

void
Expand Down
1 change: 1 addition & 0 deletions xv6-public/syscall.h
100755 → 100644
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_getpcount 22
22 changes: 22 additions & 0 deletions xv6-public/sysproc.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
#include "memlayout.h"
#include "mmu.h"
#include "proc.h"
#include "spinlock.h"

struct {
struct spinlock lock;
struct proc proc[NPROC];
} ptable;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this structure here, maybe put a function in proc.c to return the ptable

int
sys_getpcount(void)
{
struct proc *p;
acquire(&ptable.lock);
int count = 0;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
// Process states: UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE
if(p->state == SLEEPING){count++;}
else if(p->state == RUNNABLE){count++;}
else if(p->state == RUNNING){count++;}
}
release(&ptable.lock);
return count;
}

int
sys_fork(void)
Expand Down
1 change: 1 addition & 0 deletions xv6-public/user.h
100755 → 100644
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 getpcount(void);

// ulib.c
int stat(char*, struct stat*);
Expand Down
1 change: 1 addition & 0 deletions xv6-public/usys.S
100755 → 100644
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(getpcount)