Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/16

Click to flip

16 Cards in this Set

  • Front
  • Back
Why do we need the two-mode operation: user and system?
For Resource Managment
What command (or combination of commands) in the Unix(Linux) operating system can show all processes in "ready" state?
ps
Compose a program segment that can circular-shift a given character 7 positions. For example, if the given character is “A” the output should be “H”, a “Z” should produce “G”.
void decrypt(char *b,int len){
int x;
for(x=0;x<len;x++){

if (b[x]>='a' && b[x]<='s')
b[x] = b[x] + 7;
else if (b[x]>='t' && b[x]<='z')
b[x] = b[x] - 19;
else if (b[x]>='A' && b[x]<='S')
b[x] = b[x] + 7;
else if (b[x]>='T' && b[x]<='Z')
b[x] = b[x] - 19;
else
;
}

}
What system call should be used when a thread needs to wait for another thread to complete?
pthread_join()
1.Why your shell program must fork a subprocess for each user command?
When the main process needs to create a dedicated new "room" for a given task
9.What is a “race” condition?
Is a situation where two processes either communicate or share memory while they are running and the output of one or both of the processes depends on the relative speed of the two processes.
A machine requires at most 2GB memory, how wide should the address bus be?
31 bits
What is the purpose of lseek system call?
The lseek function allows the file offset to be set beyond the end of
the existing end-of-file of the file (but this does not change the size
of the file). If data is later written at this point, subsequent reads
of the data in the gap return bytes of zeros (until data is actually
written into the gap).
What do we call a millionth of a second? What do we call a billion bytes?
microsecond
nanosecond
Compose a PERL program segment that will automatically re-compile your lab1 program for N=100, 200, 300, ..., 1000 and to capture the outputs to a text file.
#!/usr/bin/perl
$MAX = 1000;
$myint = 0;
@myoptions = ("g","O","O2","O3");
open (RECORD, ">lab1.times");
for ($myint=0;$myint<=3; $myint++)
{
$OBT = @myoptions[$myint];

for ($N=100; $N<=$MAX; $N+=10)
{
system("rm *.o");
system("make OBT=@myoptions[$myint] N=$N");
$testrun = 3;
$total = 0;
for (1..$testrun)
{
open(cnt, "lab1|");
while(<cnt>) {
$total += $_;
print "time = $_\n";
}
}
$average = $total/$testrun;
$w = ($N**3)/$average; # Calculate MFLOPS
print RECORD "$N $w\n";
}

}
What is the primary benefits of including buffers in a disk controller?
Running the disks and the CPU in parallel often improves performance; therefore, it is useful to keep the CPU busy while data is being moved.
Why do we need DMA?
On first consideration of this DMA transfer cycle, it would appear that all the DMA chip does is to steal processor cycles and do I/O operations, which the main processor is quite capable of doing itself. This is all true, but for the main processor to do this transfer it would have to do so through an interrupt routine. This interrupt routine would have the overheads of being called, saving registers and being interrupted by requests with higher priority' causing it to have to save its own registers on the stack and having to be called again once the higher priority interrupt has finished. The DMA chip, on the other hand, only needs to be programmed once with however many bytes you wish to transfer and the address of where this transfer is to start from or go to. It then keeps count of how many bytes have been transferred, so there is no need to call the interrupt routine or to Pop and Push registers. This massively reduces the run-time overhead.
Where is the default header file (.h) location in a Unix system?
/usr/include/linux/file.h
Given lab4.c and lab4.h, assuming all other header files are in system default directory, create a makefile to compile a binary executable lab4
ifndef OBT
OBT = O3
endif
ifndef CC
CC = gcc
endif
ifndef N
N = 500
endif
CFLAGS += -Wall -$(OBT) -DN=$(N)
all: lab1
lab4: lab4.o
$(CC) $(CFLAGS) -o lab4 lab4.c
Compose a program that opens two files: infile and outfile. Then it copies all bytes from infile to outfile.
#include <stdio.h>
int main() {

char c[100+1];
FILE *ifile, *ofile;
ifile = fopen("encrypt.dat", "r");
ofile = fopen("clear.txt", "w");

// Check if file is valid
if(ifile==NULL) {
printf("Error: can't open file.\n");
/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
return 1;
}
//Checks output file
else if(ofile==NULL){
printf("Error - can't open output file.\n");
return 2;
}
else {
printf("File opened successfully. Contents:\n\n");
num=fread(c,sizeof(x),100,ifile);
while(num>0) {
fwrite(recvd.msg_data,sizeof(x),recvd.msg_len,ofile);

num=fread(c,sizeof(x),100,ifile);

printf("%s", recvd.msg_data);
fwrite(recvd.msg_data,sizeof(x),recvd.msg_len,ofile);

num=fread(c,sizeof(x),100,ifile);

}
// closes file
fclose(ifile);
fclose(ofile);

return 0;
}
}
Compose a program segment that will copy an input file to an output file without knowing the format of the input file. Your program must read 1024 bytes each time with proper termination and return status checks.
#include <stdio.h>
int main() {

char c[100+1];
FILE *ifile, *ofile;
ifile = fopen("encrypt.dat", "r");
ofile = fopen("clear.txt", "w");

// Check if file is valid
if(ifile==NULL) {
printf("Error: can't open file.\n");
/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
return 1;
}
//Checks output file
else if(ofile==NULL){
printf("Error - can't open output file.\n");
return 2;
}
else {
printf("File opened successfully. Contents:\n\n");
num=fread(c,sizeof(x),100,ifile);
while(num>0) {
fwrite(recvd.msg_data,sizeof(x),recvd.msg_len,ofile);

num=fread(c,sizeof(x),100,ifile);

printf("%s", recvd.msg_data);
fwrite(recvd.msg_data,sizeof(x),recvd.msg_len,ofile);

num=fread(c,sizeof(x),100,ifile);

}
// closes file
fclose(ifile);
fclose(ofile);

return 0;
}
}