CS350 COS
COS
Loading...
Searching...
No Matches
process.c File Reference
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
#include <syscall.h>
Include dependency graph for process.c:

Go to the source code of this file.

Functions

unsigned int sleep (unsigned int seconds)
 
pid_t spawn (const char *path, const char *argv[])
 
pid_t waitpid (pid_t pid, int *status, UNUSED int options)
 
pid_t wait (int *status)
 

Function Documentation

◆ sleep()

unsigned int sleep ( unsigned int  seconds)

Definition at line 12 of file process.c.

13{
14 OSThreadSleep(seconds);
15
16 // Should return left over time if woke up early
17 return 0;
18}
int OSThreadSleep(uint64_t time)
Definition: syscall.c:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawn()

pid_t spawn ( const char *  path,
const char *  argv[] 
)

Definition at line 21 of file process.c.

22{
23 uint64_t status = OSSpawn(path, argv);
24
25 if (SYSCALL_ERRCODE(status) != 0) {
26 errno = SYSCALL_ERRCODE(status);
27 return -1;
28 }
29
30 return (pid_t)SYSCALL_VALUE(status);
31}
#define errno
Definition: errno.h:7
uint64_t OSSpawn(const char *path, const char *argv[])
Definition: syscall.c:29
#define SYSCALL_ERRCODE(_result)
Definition: syscall.h:56
#define SYSCALL_VALUE(_result)
Definition: syscall.h:57
unsigned long uint64_t
Definition: types.h:13
uint16_t pid_t
Definition: types.h:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait()

pid_t wait ( int *  status)

Definition at line 49 of file process.c.

50{
51 return waitpid(WAIT_ANY, status, 0);
52}
pid_t waitpid(pid_t pid, int *status, UNUSED int options)
Definition: process.c:34
#define WAIT_ANY
Definition: wait.h:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitpid()

pid_t waitpid ( pid_t  pid,
int *  status,
UNUSED int  options 
)

Definition at line 34 of file process.c.

35{
36 uint64_t wstatus = OSWait(pid);
37
38 if (SYSCALL_ERRCODE(wstatus) != 0) {
39 errno = SYSCALL_ERRCODE(wstatus);
40 return -1;
41 }
42
43 *status = SYSCALL_VALUE(wstatus) & 0x0000ffff;
44
45 return WGETPID(SYSCALL_VALUE(wstatus));
46}
uint64_t OSWait(uint64_t pid)
Definition: syscall.c:35
#define WGETPID(_x)
Definition: wait.h:13
Here is the call graph for this function:
Here is the caller graph for this function: