This site is 100% ad supported. Please add an exception to adblock for this site.

interview 2

Terms

undefined, object
copy deck
A thread consists of four subcomponents:
a program counter
a collection of variables that can only be accessed by the thread,
a collection of variables that can be accessed by the thread in question and other threads, and
a set of synchronization primitives that allow one thread to unambiguously influence the program counter of another.
local state
global state
Variables that can be accessed only by the thread are called local state.

Variables that can be accessed by more than one thread are typically called global state
threads Vs. process
threads share variables

processes are disjoint
pthread_create

exit
int pthread_create(pthread_t *new_thread_ID,
const pthread_attr_t *attr,
void * (*start_func)(void *),
void *arg);

int pthread_join(pthread_t target_thread,
void **status);


return or pthread_exit()
different machine architectures use different binary representations for integers and floating point numbers.
little endian

big endian
network byte order
convert you addresses to a canonical byte ordering that all architectures can then convert to a local representation
uint32_t htonl(uint32_t host_long);

uint16_t htons(uint16_t host_short);
uint32_t ntohl(uint32_t net_long);

uint16_t ntohs(uint16_t net_short);
open socket
#include < sys/socket.h >

int tcp_sd;
int udp_sd;

tcp_sd = socket(AF_INET, SOCK_STREAM, 0);
udp_sd = socket(AF_INET, SOCK_DGRAM, 0);

ret_val = -1 for failure
socket strcuture
struct sockaddr_in {
uint_8 sin_len; /* length of structure (16) */
sa_family_t sin_family; /* address family is AF_INET for IP */
in_port_t sin_port; /* port number (UDP/TCP)
struct in_addr sin_addr; /* IP address */
char sin_zero[8]; /* unused */
};
server side socket:
open ( socket() )
bind()
listen()
accept()
bind
#include < netinet/in.h >

bind(tcp_sd, (struct sockaddr *)&sa, sizeof(sa));
listen
listen(tcp_sd, 5);

5:# of connections
accept
new_sd = accept(tcp_sd, (struct sockaddr *)&remote_addr, sizeof(remote_addr));

tcp_sd: server socket
new_sd: active socket
client side socket:
socket
bind
connect

Deck Info

14

permalink