CS360: Final Exam: 12/13/97. Cheat Sheet
Basic System calls for I/O
int read(int fd, char *buf, int size);
int write(int fd, char *buf, int size);
int close(int fd);
Red-black trees
Rb_node make_rb(); /* Creates a new rb-tree */
Rb_node rb_insert(Rb_node tree, char *key, char *val);
rb_delete_node(Rb_node node);
#define rb_first(n) (n->c.list.flink)
#define rb_last(n) (n->c.list.blink)
#define rb_next(n) (n->c.list.flink)
#define rb_prev(n) (n->c.list.blink)
#define rb_nil(t) (t)
#define rb_traverse(ptr, lst) \
for(ptr = rb_first(lst); ptr != rb_nil(lst); ptr = rb_next(ptr))
Sockets
extern int serve_socket(char *hn, int port);
extern int accept_connection(int s);
extern int request_connection(char *hn, int port);
Various Stuff
int fork();
int pipe(int p[2]);
int dup2(int fd1, int fd2);
int wait(int *statusp);
int execlp(char *fn, char *arg0, char *arg1, ..., NULL);
memcpy(char *to, char *from, int nbytes);
Select()
int select(int nfds, fd_set *readfds, fd_set *wrfds, fd_set *efds, NULL);
fd_set fdset;
FD_SET(fd, &fdset);
FD_CLR(fd, &fdset);
FD_ISSET(fd, &fdset);
FD_ZERO(&fdset);
Threads
int pthread_create(pthread_t *t, NULL, function, void *args);
int pthread_mutex_init(pthread_mutex_t *lock);
int pthread_mutex_lock(pthread_mutex_t *lock);
int pthread_mutex_unlock(pthread_mutex_t *lock);
int pthread_exit(void *retval);
int pthread_join(pthread_t target_thread, void **status);