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.
Selective repeat protocol
This protocol also provides 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, and so is also called
Selective Repeat sliding window protocol
Describe three ways in which Go Back N protocol differs from Selective repeat protocol.
Acknowledgements: The receiver in the Go back N protocol sends a NAK to indicate that a packet was not received correctly and a range of packets are resent after one NAK. The receiver in selective repeat can individually acknowledge packets and then NAK packets are individually resent by sender
Implementation of Go back N is easier to implement as it takes up less memory than selective repeat
Retransmission: Go back N is less efficient as due to even one NAK it has to resend the range of packets, but with Selective repeat packets can be resent efficiently