Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/kern/include/proc.h
2093 views
1
#ifndef __PROC__
2
#define __PROC__
3
4
#include <types.h>
5
#include <filedesc.h>
6
#include <synch.h>
7
8
#define MAX_PROCESSES 32
9
#define PROC_RESERVED_SPOT 0xcafebabe
10
#define PROC_MAX_HEAP_PAGES 2048
11
12
struct proc {
13
pid_t p_pid; /* pid of the process */
14
struct filedesc *p_fd; /* file descriptor table */
15
struct proc *p_proc; /* parent process */
16
bool p_is_dead; /* are we dead? */
17
int p_retval; /* our return code */
18
19
/* synchronization mechanisms */
20
struct lock *p_lk; /* lock to protect the structure */
21
struct semaphore *p_sem; /* sem used for wait/exit */
22
23
/* scheduler related */
24
uint64_t p_nsyscalls; /* how many system calls we called? */
25
int p_nice; /* our nice value */
26
};
27
28
extern struct proc *allproc[MAX_PROCESSES];
29
extern struct lock *lk_allproc;
30
extern struct lock *lk_exec;
31
32
int proc_create( struct proc ** );
33
int proc_clone(struct proc *, struct proc ** );
34
void proc_destroy(struct proc *);
35
int proc_get( pid_t, struct proc ** );
36
void proc_system_init(void);
37
38
//tests.
39
void proc_test_pid_allocation(void);
40
41
#define PROC_LOCK(x) (lock_acquire( (x)->p_lk ))
42
#define PROC_UNLOCK(x) (lock_release( (x)->p_lk ))
43
44
#endif
45
46