Enums, Sockets, Threads Flashcards
Define what an Enumeration is, as well as it’s purpose…
A way of specifying a set of integer constants, each of which is represented by a variable name.
What is the default start value of Enums? What happens if you assign a different integer to the first value?
- If the first number is changed, the following numbers will be be incremented accordingly.
In an enum of 10 members, if the first 5 constants are 0-5 integers, but then the 5th is changes to 88. What will the integer constants of 5 to 10 be?
88,89,90,91,92
Write a small program to give an example of an Enumeration…
…
What does the telnet command do? Give an example of telnet in use…
telnet connects the terminal to a remote server e.g. telnet computerscience.ac.uk 80
Define the roles of sockets on a network…
Sockets enable nodes (hosts) on a network to communication with each other.
In most systems that use sockets, what language is the fundamental low-level socket that peripheral sockets all filter down to developed in?
Most systems have a core C socket, which other sockets filter down to.
What are the 2 sides of a Socket interaction across a network called?
Client Server.
What are the 7 steps that a Server Side socket conducts to interact with a Client Socket?
Create socket; set socket options; Bind listener to port number; Listen; Accept client request; Exchange data; Close connection.
What are the 3 steps that a Client Side socket conducts to interact with a Server socket?
Create socket; Request a connection; Exchange data.
When a Server Socket is listening on a port, what type of process is doing the listening?
Http Daemon process listens for connection on the socket port.
What is a daemon process in Linux?
A background process
Which of the fundamental processes is used to enable data exchange between the 2 sockets?
Pipe
Which command is used to create a pipe between a pair of sockets?
popen( ) -> Pipes between 2 sockets.
With regards to exchanging data, what is the difference between using pipes as opposed to raw sockets?
Using popen( ) opens a buffered stream between sockets. Thus, it’s safer and quicker.
Since C doesn’t have native threading, which API does it use or threading?
POSIX -> Portable OS Interface
What is pthreads? Where is it utilised?
pthreads is a multi-threading model used by many modern languages, and exists independently of any language.
Which statement would be used to declare 3 threads?
pthread_t -> e.g pthread_t my_threads(3);
What is mutex? What problem does it solve? What issue can it cause?
Locks a resource so only 1 thread can execute on it at any given time. However, Causes idle time for waiting threads.
What signalling mechanism do we use to signal that a resource is free for a thread to use?
Semaphore
What value does semaphore return to indicate that the resource is free?
Non-zero. If the semaphore returns a non-zero value, the resource is free.