--- tags: NSYSU, 網路系統程式, 網程 --- # 網路系統程式設計期末考筆記 [TOC] ## variables time_t struct tm struct timeval pid_t struct utsname ## functions | | Give Absolute Path | Use PATH Variable | New Environment | | -------- | -------- | -------- | -------- | | argv as list | execl() | execlp() | execle()| | argv as vector | execv() | execvp() | execve()| |Function|Description| |-----|------| |exit() | Flushes buffers and calls _exit() to terminate process| _exit()| Closes files and terminates process atexit()| Stores function for future execution before terminating a process abort()| Closes files, terminates the process, and produces a core dump for debugging ### Memory allocation |Function|Description| |--------|-----------| malloc()| Allocates memory free()| Frees memory realloc()| Changes the memory allocate ### String manipulation |Function|Description| |--------|-----------| strcpy() |Copies the character string pointed to by src, including the null terminator, to the character array whose first element is pointed to by dest. strcat() | strlen() | strdup() |allocate a copy of a string up to specified size strstr() |Finds the first occurrence of the null-terminated byte string pointed to by substr in the null-terminated byte string pointed to by str. The terminating null characters are not compared. strpbrk()|Scans the null-terminated byte string pointed to by dest for any character from the null-terminated byte string pointed to by breakset, and returns a pointer to that character. strtok() |Finds the next token in a null-terminated byte string pointed to by str. The separator characters are identified by null-terminated byte string pointed to by delim. strspn() |Returns the length of the maximum initial segment (span) of the byte string pointed to by dest, that consists of only the characters found in byte string pointed to by src. ### host information |Function|Description| |--------|-----------| uname()| Retrieves host name and other related information sysinfo()| Reports and sets information about the operating system ### machine time |Function|Description| |--------|-----------| time()|Returns number of seconds since 0:00:00, January 1, 1970 gettimeofday()| Returns time in seconds and microseconds ctime()| Returns time in a human readable format gmtime()|Breaks time from time() into fields from seconds to years, Greenwich mean time localtime()| Same as gmtime() except local time strftime()| Returns time in customized string format ### process related |Function|Description| |-----|------| wait()| Blocks the process until one of its children is ready to have its status reaped. waitpid() | Allows you to specify which process to wait for and whether to block getuid()| Retrieves user identification numbers geteuid()| Retrieves effective user ID getgid()| Retrieves real group user ID geteguid()| Retrieves effective group user ID getpwuid()|Retrieves the user identification number from the password database getpwnam()|Retrieves the user name from the password database getpid()| Retrieves process ID number getppid()| Retrieves parent PID getpgrp()| Retrieves process group ID number getpgid()| Retrieves process group GID ### Environment variables |Function|Description| |-----|------| getenv()| Retrieves the value of an environment variable putenv()| Adds variables to the environment unsetenv()| Removes an environment variable ## image ![](https://i.imgur.com/4lYTCU6.png) ![](https://i.imgur.com/4jYOJ3q.png) ![](https://i.imgur.com/YSXHMnl.png) ![](https://i.imgur.com/SaWlKM0.png) ![](https://i.imgur.com/uEcKqP6.png) ## comparable table |System Call | Library Call| |------------|-------------| Never allocates space for parameters. |Can allocate space for parameters (see man pages). If allocates space, it can be static or dynamic. Executes in system mode (kernel mode).| Executes in user mode. When a failure occurs: Returns -1. Sets errno(so you can use perror(3C)). |When a failure occurs: Often returns NULL (see man pages). Can set errno (see man pages) # Tracing functions tool: truss — Traces system calls made by a process + How to run: + $truss <args to truss> <pgm> <pgm args> + $truss -p <pid_of_running_pgm> <args to truss> + args to truss include: + Trace output redirection + Specification of certain system calls + Address argument dereferencing (>= 2.7) + Library calls (>= 2.7)