mock test Flashcards
What are the 2 main functions of the OS
Extended machine - an abstraction of heterogeneous underlying hardware
Resource manager - managing and sharing hardware such as I/O devices and memory
What is the text segment of the process address space used for
It is used to store the instructions of the program that are executed by the CPU.
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
Where is the process address space in len located
data segment
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
When will the memory used by len be available for reuse
process termination
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
In which area of the process address space is ai allocated
stack
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
When will the memory used by ai be available for reuse
function return
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
Where in the process address space is the memory pointed to by pai
heap
int *my_function(void) {
static int len = 10;
int ai[len];
int *pai = (int *) calloc(len, sizeof(int));
// other code is omitted
return pai;
}
When will the memory pointed to by pai be available for reuse
program exit
include <stdio.h></stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXSTR 256
struct business {
char* name;
int reg;
int tel;
char type;
};
int main(void) {
struct business b;
b.name = (char*) malloc(strnlen("Newcastle Widgets", MAXSTR - 1) + 1);
snprintf(b.name, MAX_STR, "%s", "Newcastle Widgets");
b.reg = 1234;
b.tel = 1912089000;
b.type = 'x';
// other program code omitted for brevity</stdlib.h></string.h>
free(b.name); return 0; } On a 32 bit machine with 32 bit ints, what is the sum in bytes of the sizes of the fields of the business struct?
On a 32-bit machine with 32-bit integers, the size of the char* field name in the business struct is 4 bytes, because a pointer to a char occupies 4 bytes on a 32-bit machine.
The size of the int field reg is 4 bytes, because an int is 4 bytes on a 32-bit machine.
The size of the int field tel is also 4 bytes, for the same reason.
The size of the char field type is 1 byte, because a char is 1 byte on a 32-bit machine.
The sum of the sizes of the fields of the business struct is therefore 4 + 4 + 4 + 1 = 13 bytes.
Briefly explain why CSMA protocols provide a better utilisation than Aloha protocols?
CSMA (Carrier Sense Multiple Access) protocols provide better utilization than Aloha protocols because they allow a node to only transmit when the channel is idle, rather than transmitting regardless of the state of the channel. This reduces the likelihood of collisions, which in turn increases the overall efficiency of the network.
Describe the operation of the P-persistent CSMA protocol?
When a host becomes ready to send, it senses the channel. If it is idle, it transmits with a probability p
If that slot is also idle, it either transmits or defers again, with probabilities p and q respectively
If a slot is busy, it waits a random amount of time and starts again
Flow control formula
Frame Transmission time (seconds) = Frame size (bits) / Transmission rate (bits/sec)
Selective repeat Protocol calc
Transmission rate * 2
Go back N protocol calc
Transmission rate + 1
go back N protocol
-It allows for sending N frames before receiving the acknowledgement for the first frame
-The frames are sequentially numbered
-It uses the concept of sliding windows at the sender and the receiver.