For each of the functions - short description, return value, parameters ** System calls ** ** Functions marked ** are wrappers for lower level system calls ** System calls return 0 on success and - 1 on error (and set errno code), unless otherwise specified. + Processes + fork - creates a duplicate of the process with both processes being identical except for the return value from fork. Returns 0 in child and pid of child in parent. No parameters. execv** - replaces the program code for the current process with program code from a file. No return if successful, -1 return if error. Parameters - path to file image, argv arguments. + Files + open - open and possibly create a file. Returns file descriptor, -1 on error. Parameters - path to file, flags close - close a file descriptor (could be a file or socket). Parameter - file descriptor. read - read from a file descriptor (could be a file or socket). Returns # bytes read, 0 for EOF, -1 for error. Parameters - file descriptor, pointer to buffer, size of buffer. write - write to a file descriptor (could be a file or socket). Return/parameters - same as read. unlink - remove reference to a given file from a directory (similar to rm, rm is based on unlink). + Utilities for files, sockets + FD_ZERO - init file descriptor set to be all zeros. No return. Parameters - ponter to fd set. FD_SET - set a file descriptor bit in an fd set. No return. Parameters - fd, pointer to fd set. FD_CLR - clear a file descriptor bit in an fd set. No return. Parameters - same as FD_SET. FD_ISSET - check if a file descriptor bit is set in an fd set. Returns # of fd's with bits set in return. Parameters - fd, pointer to fd set that has bits set by function. select - check whether any fd's in an fd set have data ready to read, write. Returns # fd's with bits set in return. Parameters - max fd # to check + 1, pointers to fd sets for read / write / except, pointer to timeout struct. + Network + gethostbyname - convert from a hostname (e.g., cs.indstate.edu) to a network (IP) address. OBSOLETE. Returns pointer to hostent structure. Parameters - name to lookup. htons - host to network short, changes byte order from what this machine uses to what the internet standard uses. Returns short. Parameter - short. + Pipes, sockets in general + pipe - creates a pipe that allows one-way communication between two processes. Parameters - address to pass back pair of file descriptors. socketpair - creates two pipes to allow two-way communictaion between processes. Parameters - domain (AF_UNIX), type, protocol, address to pass back pair of file descriptors. socket - create a file descriptor for a socket. Returns file descriptor on success, -1 on error. Parameters - domain (unix, inet, etc.), type (stream, datagram, etc.), protocol. getsockname - returns address of a given socket. Parameters - file descriptor, pointer to structure for return, pointer for length of structure to return. + Sockets for server + bind - bind a socket to a specific name (either a named socket in the file system, or a port). Parameters - same as getsockname (bind passes in, getsockname sends them back). listen - set a socket to be one that can accept incoming connections. Parameters - file descriptor, size of backlog. accept - wait for an incoming connection to a socket. Parameters - same as bind. + Sockets for client + connect - initiate socket connection (to a given address). Parameters - same as bind. sendto - send to a given socket at a specified name/address. Returns - # bytes sent, or -1 for error. Parametes - file descriptor, pointer to buffer, length of buffer, flags, pointer to structure with socket address, length of socket address structure. ** C standard library ** perror - lookup error string for current error, write to stderr. No return. Parameter - address of string. bcopy - binary copy, copy from one memory address to another. No return. Parameters - source pointer, destination pointer, # bytes to copy. bzero - binary zero, set a chunk of memory to 0's. No return. Parameters - pointer, # bytes to zero. strcpy - copy a C string from one address to another, string must be NULL-terminated. Returns address of destination. Parameters - destination pointer, source pointer. printf - print formatted to stdout. Returns # characters printed. Parameters - format string, parameters to the format string. Unix process - a running program * process id * its own virtual memory (note - own memory for security, convenience) * permissions and such * program counter - where in the program is it currently running * file descriptors - like an excel table of my open files, descriptors are row numbers in excel Descriptor#, path, location in file, type of thing 0, stdin, NA, 1, stdout, NA, 2, stderr, NA, 5, /u1/junk/hello.txt, 0 20, /proc/cpuinfo, 123 21, /u1/junk/shakespeare.txt, 0 23, NA, NA, socket (and info about the socket)