API Flashcards

(39 cards)

1
Q

fork

A

int fork(void);
create a new process that is an exact copy of the old process
- returns pid of new process in parent
- returns 0 in child
gets called once, returns twice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

waitpid

A

int waitpid(int pid, int * status, int options);
attempt to get exit status of child
- returns pid or -1 on error
- pid = pid to wait for, -1 for any
- status = exit value/signal of child
- options = 0 means wait for child to terminate, WNOHANG means do not wait

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

exit

A

void exit(int status);
exit the current process
- status = shows up if waitpid called
0 is success, non-zero is failure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

kill

A

int kill(int pid, int sig);
sends signal to a process
- pid = pid of target
- sig = code
SIGTERM most common, kills process by default but app can catch for cleanup
SIGKILL is stronger, always kills

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

execve

A

int execve(char * prog, char ** argv, char ** envp);
replace the current program with a new one
- prog = path to new program
- argv = arguments to prog’s main
- envp = environment for new program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

execvp

A

int execvp(char * prog, char ** argv);
searches PATH for prog, uses current environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

execlp

A

int execlp(char * prog, char * arg, …);
execvp, but listing each argument terminated by NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

dup2

A

int dup2(int oldfd, int newfd);
makes newfd an exact copy of oldfd
closes newfd, if it was valid
both fds share the same offset (lseek on one affects both)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

pipe

A

int pipe(int fds[2]);
output of fds[1] is input to fds[0]
- returns 0 on success, -1 on error
- when fds[1] is invalidated, fds[0] returns EOF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

x86 lock

A

makes the following instruction atomic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

x86 lfence

A

waits for all reads to be done before continuing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

sfence

A

waits for all writes to be done before continuing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

mutex_lock implementation

A

while(xchg(mutex, true)) {};
uses atomic test and set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

_Atomic

A

wrap most basic types with _Atomic() and all standard operations are seqcon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

atomic_flag

A

special type:
- atomic bool, no load/store
- uses test_and_set or clear instead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

relaxed

16
Q

consume

A

slightly relaxed acquire

17
Q

acquire

A

reads/writes after the load cannot be reordered before

18
Q

release

A

reads/writes before the store cannot be reordered after

19
Q

acq_rel

A

acquire and release

20
Q

seq_cst

21
Q

how syscalls are performed

A
  1. load syscall args into registers
  2. load syscall number into rdi
  3. int 60 (T_SYS = 60)
  4. interrupt handler looks to IDT for entry point
  5. jumps to the entry point
22
Q

TLB instructions

A

tlbwr, tlbwi, tlbr, tlbp
to use each, load:
c0_entryhi
c0_entrylo
c0_index

23
Q

tlbwr

A

TLB write a random slot

24
tlbwi
TLB write a specific slot
25
tlbr
TLB read a specific slot
26
tlbp
probe the entry that matches c0_entryhi
27
brk
char * brk(const char * addr); - set and return new value of breakpoint
28
sbrk
char * sbrk(int incr); - increment value of the breakpoint and return the old value
29
mmap
void * mmap(void * addr, size_t len, int prot, int flags, int fd, off_t offset); - treat a file as if it were memory - map the file fd to the virtual address addr, except that changes are backed up to the file - file can be shared with other processes - addr = NULL, let kernel choose addr - prot specifies protection of region (PROT_EXEC | PROT_READ | PROT_WRITE | PROT_NONE) - flags: MAP_SHARED - modifications seen by everyone, MAP_PRIVATE - modifications are private, MAP_ANON - anonymous memory (no file associated with this address range)
30
munmap
int munmap(void * addr, size_t len); - remove mmapped object from address space
31
mprotect
int mprotect(void * addr, size_t len, int prot); - change protection on pages to prot
32
msync
int msync(void * addr, size_t len, int flags); flush changes of mmapped file to backing store i.e. the file
33
mincore
int mincore(void * addr, size_t len, char * vec); - return which pages present in RAM (i.e. core) vs swap space in vec
34
madvise
int madvise(void * addr, size_t len, int behav); - advise the OS on memory use e.g. MADV_RANDOM (don't prefetch) vs MADV_SEQUENTIAL - MADV_WILLNEED or MADV_DONTNEED (don't prefetch)
35
sigaction
int sigaction(int sig, const struct sigaction * act, struct sigaction * oact); - specify what function to call for SIGSEGV or other signals - if oact not null, save the old sigaction in oact
36
p_nice
user-set weighting factor in [-20, 20], negative -> higher priority
37
p_estcpu
per-process estimated CPU usage - incremented whenever it got preempted - decayed every second while process runnable
38
load (with p_nice, p_estcpu)
the sampled average length of the run queue + short term sleep queue over last minute - the higher the load, the less p_estcpu is reduced