JMU CS 361 Final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/64

flashcard set

Earn XP

Description and Tags

Everything from the PDF provided by Dr. Kirkpatrick 😋😋😋😋😋

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

65 Terms

1
New cards

accept

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

Accepts an incoming connection on a listening socket. Returns a new connected socket.


Ex: accept(server_fd, (struct sockaddr *)&cli, &len);

2
New cards

bind

int bind(int socket, const struct sockaddr *address, socklen_t address_len);

Assigns an IP/port to a socket.

Ex: bind(fd, (struct sockaddr *)&addr, sizeof(addr));

3
New cards

calloc

void* calloc(size_t num, size_t size);

Allocates zero-initialized memory.

Ex: int *a = calloc(10, sizeof(int));

4
New cards

close

int close(int fd);

-
Closes a file descriptor or socket.

5
New cards

connect

int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
-
Initiates a connection to a remote socket.
-
Ex: connect(fd, (struct sockaddr *)&server, sizeof(server));

6
New cards

dup2

int dup2(int oldfd, int newfd);

-

Duplicates a file descriptor to a specific fd number. dup2(fd, STDOUT_FILENO);

7
New cards

execl

int execl(const char *path, const char *arg, ...);

-

Executes a program.

-

execl("/bin/ls", "ls", "-l", NULL);

8
New cards

execle

int execle(const char *path, const char *arg, ..., char * const envp[]);

-

Executes a program with custom environment.

-

execle("/bin/ls", "ls", NULL, envp);

9
New cards

execlp

int execlp(const char *file, const char *arg, ...);

-

Executes using PATH search.

-

execlp("ls", "ls", "-a", NULL);

10
New cards

execv

int execv(const char *path, char *const argv[]);

-

Executes program with argv.

-

execv("/bin/ls", (char *[]){"ls", "-l", NULL});

11
New cards

execve

int execve(const char *path, char *const argv[], char *const envp[]);

-

Executes program with environment.

-

execve("/bin/ls", argv, envp);

12
New cards

execvp

int execvp(const char *file, char *const argv[]);
-

Executes using PATH.
-

execvp("ls", argv);

13
New cards

fork

pid_t fork(void);

-

Creates a new process. pid == 0 is child, < 0 failed, else parent

-

pid_t pid = fork();

14
New cards

free

void free(void *ptr);

-

Frees allocated memory.

-

free(p);

15
New cards

fstat

int fstat(int fd, struct stat *buf);

-

Gets file info from file descriptor.

-

fstat(fd, &st);

16
New cards

getaddrinfo

int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);

-

Hostname/IP resolution.

-

getaddrinfo("localhost", "80", &hints, &res);

17
New cards

getenv

char *getenv(const char *name);

-

Gets environment variable.

-

char *p = getenv("PATH");

18
New cards

getpid

pidt getpid(void);

-

Returns current process ID.

-

pidt pid = getpid();

19
New cards

getppid

pidt getppid(void);

-

Returns parent process ID.

-

pidt p = getppid();

20
New cards

htonl

uint32t htonl(uint32t hostlong);

-

Host to network (32-bit).

-

uint32_t v = htonl(1234);

21
New cards

htons

uint16t htons(uint16t hostshort);

-

Host to network (16-bit).

-

uint16_t p = htons(80);

22
New cards

inet_addr

inaddrt inetaddr(const char *cp);

-

String IPv4 to binary.

-

ip.saddr = inet_addr("127.0.0.1");

23
New cards

inet_aton

int inetaton(const char *cp, struct inaddr *inp);

-

Parses IPv4.

-

inet_aton("1.2.3.4", &addr);

24
New cards

inet_ntoa

char *inetntoa(struct inaddr in);

-

Binary IPv4 to string.

-

printf("%s", inet_ntoa(addr));

25
New cards

inet_ntop

const char *inetntop(int af, const void *src, char *dst, socklent size);

-

Binary IP → string.

-

inetntop(AFINET, &addr, buf, sizeof(buf));

26
New cards

kill

int kill(pid_t pid, int sig);

-

Sends signal to process.

-

kill(pid, SIGTERM);

27
New cards

listen

int listen(int sockfd, int backlog);

-

Marks socket as passive.

-

listen(fd, 10);

28
New cards

malloc

void *malloc(size_t size);

-

Allocates memory.

-

int *p = malloc(sizeof(int));

29
New cards

memcpy

void *memcpy(void *dest, const void *src, size_t n);

-

Copy memory.

-

memcpy(buf2, buf1, 100);

30
New cards

memset

void *memset(void *s, int c, size_t n);

-

Fill memory with value.

-

memset(buf, 0, 256);

31
New cards

mkfifo

int mkfifo(const char *pathname, mode_t mode);

-

Creates named pipe.

-

mkfifo("pipe1", 0666);

32
New cards

mmap

void *mmap(void *addr, sizet length, int prot, int flags, int fd, offt offset);

-

Maps file to memory.

-

ptr = mmap(NULL, 4096, PROTREAD, MAPPRIVATE, fd, 0);

33
New cards

msync

int msync(void *addr, sizet length, int flags);

-

Syncs mmap to disk.

-

msync(ptr, 4096, MSSYNC);

34
New cards

ntohl

uint32t ntohl(uint32t netlong);

-

Network → host (32-bit).

-

v = ntohl(n);

35
New cards

hawk tuah

spit on that thang!!!

<p>spit on that thang!!!</p>
36
New cards

ntohs

uint16t ntohs(uint16t netshort);

-

Network → host (16-bit).

-

p = ntohs(n);

37
New cards

open

int open(const char *pathname, int flags, …);

-

Opens a file.

-

fd = open("file.txt", O_RDONLY);

38
New cards

pipe

int pipe(int pipefd[2]);

-

Creates a pipe.

39
New cards

posix_spawn

int posix_spawn(pidt *pid, const char *path, …);

-

Spawns a process.

-

posix_spawn(&pid, "/bin/ls", NULL, NULL, argv, envp);

40
New cards

pthread_create

int pthread_create(pthread_t *thread, const pthread_attrt *attr, void (start_routine)(void *), void *arg);

-

Creates thread.

-

pthread_create(&t, NULL, func, NULL);

41
New cards

pthread_exit

void pthread_exit(void *retval);

-

Ends calling thread.

-

pthread_exit(NULL);

42
New cards

pthread_join

int pthread_join(pthread_t thread, void **retval);

-

Waits for a thread.

-

pthread_join(t, NULL);

43
New cards

pthreadmutexlock

int pthread_mutex_lock(pthreadmutext *mutex);

-

Locks mutex.

-

pthreadmutexlock(&m);

44
New cards

pthreadmutexunlock

int pthread_mutex_unlock(pthread_mutext *mutex);

-

Unlocks mutex.

-

pthread_mutex_unlock(&m);

45
New cards

read

ssizet read(int fd, void *buf, sizet count);

-

Reads bytes from fd.

-

read(fd, buf, 100);

46
New cards

realloc

void *realloc(void *ptr, size_t size);

-

Resizes memory.

-

p = realloc(p, 200);

47
New cards

recv

ssize_t recv(int sockfd, void *buf, sizet len, int flags);

-

Receives data.

-

recv(fd, buf, 256, 0);

48
New cards

Dr. Kirkpatrick’s Belly

knowt flashcard image
49
New cards

recvfrom

ssize_t recvfrom(int sockfd, void *buf, sizet len, int flags, struct sockaddr *src, socklen_t *srclen);

-

Receives UDP datagram.

-

recvfrom(fd, buf, 256, 0, (struct sockaddr *)&cli, &len);

50
New cards

sem_init

int seminit(semt *sem, int pshared, unsigned int value);

-

Initializes semaphore.

-

sem_init(&sem, 0, 1);

51
New cards

sem_post

int sempost(semt *sem);

-

Increments semaphore.

-

sem_post(&sem);

52
New cards

sem_wait

int semwait(semt *sem);

-

Decrements semaphore.

-

sem_wait(&sem);

53
New cards

send

ssizet send(int sockfd, const void *buf, sizet len, int flags);

-

Sends data.

-

send(fd, "hi", 2, 0);

54
New cards

sendto

ssize_t sendto(int sockfd, const void *buf, sizet len, int flags, const struct sockaddr *dest, socklen_t destlen);

-

Sends UDP datagram.

-

sendto(fd, msg, mlen, 0, (struct sockaddr *)&addr, sizeof(addr));

55
New cards

sigaction

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);

-

Installs signal handler.

-

sigaction(SIGINT, &sa, NULL);

56
New cards

LOL!!! TROLL CARD!!!

knowt flashcard image
57
New cards

snprintf

int snprintf(char *str, size_t size, const char *format, …);

-

Formatted output (safe).

-

snprintf(buf, 64, "x=%d", x);

58
New cards

stat

int stat(const char *path, struct stat *buf);

-

Gets file metadata.

-

stat("file.txt", &st);

59
New cards

strdup

char *strdup(const char *s);

-

Duplicate string.

-

char *p = strdup("hello");

60
New cards

strncat

char *strncat(char *dest, const char *src, size_t n);

-

Append n chars.

-

strncat(a, b, 5);

61
New cards

strncpy

char *strncpy(char *dest, const char *src, size_t n);

-

Copy up to n chars.

-

strncpy(buf, src, 10);

62
New cards

strtok

char *strtok(char *str, const char *delim);

-

Tokenize string.

-

char *tok = strtok(s, " ");

63
New cards

wait

pid_t wait(int *status);

-

Waits for child.

-

wait(NULL);

64
New cards

waitpid

pid_t waitpid(pidt pid, int *status, int options);

-

Waits for specific child.

-

waitpid(pid, NULL, 0);

65
New cards

write

ssize_t write(int fd, const void *buf, sizet count);

-

Writes bytes to fd.

-

write(fd, "hi", 2);