Course: Computer Science. Module: 207SE Operating Systems, Security and Networks. Submission data: 3 rd March. Portfolio 1

Size: px
Start display at page:

Download "Course: Computer Science. Module: 207SE Operating Systems, Security and Networks. Submission data: 3 rd March. Portfolio 1"

Transcription

1 Name: Conor Flanagan Student id: Course: Computer Science Module: 207SE Operating Systems, Security and Networks Submission data: 3 rd March Portfolio 1

2 Lab Activity 1 Operating Systems Tasks and Programming a) In one paragraph describe what you feel the future of operating systems will be. You might include diagrams to support your predictions and describe how the future operating systems will differ from the current one. In the past, operating systems have been developed upon hardware available at the time of creation, needing to be rebuilt each time technology advanced (such as the development of integrated circuits over transistors), often causing prior data and systems to be unusable and obsolete (ComputerWorld 2003). The increase in significance and volume of data in today s world means that backwards compatibility is crucial for any new systems in order to preserve current data. In the future, the deceleration of software and hardware developments combined with streamlining of hardware means that OSes can and will build upon previous implementations; each new OS being a derivation of previous systems (like Android being a derivation of Linux, which in itself is derived from UNIX), primarily changing the method of interaction a user has with the system, while the background systems remain largely similar (Medium 2016). b) Programming activity (b1). def grammarcheck(): agent = ('bot', 'mike') action = ('pick','put','lift','drop','go') direction = ('forward','backwards','left','right') pronoun = ('I','you','we') objects = ('nuts','plum','cat','cup') colour = ('red','blue') initial = input("enter string to parse: ") wordlist = list() for w in initial.split(' '): #Split string into words using spaces to identify words wordlist.append(w) #Insert word at start of the list print(wordlist) #Print individual words as a list print(" ") while True: if wordlist[0] not in agent and wordlist[0] not in pronoun: print("grammar incorrect") break #If sentence does not start with an agent or pronoun else: if wordlist[1] not in action: print("grammar incorrect") break #If agent not followed by action else: if wordlist[2] not in objects and wordlist[2] not in direction and (wordlist[0] in pronoun and wordlist[2] in colour): print("grammar incorrect") break else: if wordlist[0] in agent and wordlist[2] in colour: if len(wordlist) <= 3: print("grammar correct") break elif wordlist[3] not in objects: print("grammar incorrect") break elif len(wordlist) <= 4: print("grammar correct") break else: print("grammar incorrect") elif len(wordlist) <= 3: print("grammar correct") break else: print("grammar incorrect") break print(" ") grammarcheck() if name == " main ": grammarcheck() #Run program again

3 Code output using example sentences provided:

4 Lab Activity 2 Linux Command Line (Commands and outcomes from a series of small tasks that require use of a number of Linux commands) a) Create a directory (Portfolio1) in home directory, make it read/write/executable for you and your group, executable for others. Show evidence with ls command. ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ mkdir Portfolio1 ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ chmod 711 Portfolio1 ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ ls lab2.txt [0m[01;34mPortfolio1[0m b) Download the script at to your home directory using wget and make it executable. ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ wget :44: Resolving ( Connecting to ( :80... connected. HTTP request sent, awaiting response Moved Permanently Location: [following] :44: Resolving centerkey.com (centerkey.com) Reusing existing connection to HTTP request sent, awaiting response OK Length: 2107 (2.1K) [text/plain] Saving to: â tree.shâ tree.sh 0%[ ] KB/s tree.sh 100%[==================================================================== ==============================================>] 2.06K --.-KB/s in 0s :44:19 (178 MB/s) - â tree.shâ saved [2107/2107] ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ chmod tree.sh x ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ mkdir bin ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ cd bin ]0;flanag20@hvs-its-lnx01: ~/binflanag20@hvs-its-lnx01:~/bin$ mv ~/tree.sh./ ]0;flanag20@hvs-its-lnx01: ~/binflanag20@hvs-its-lnx01:~/bin$ chmod 755 tree.sh c) Making Directories Create a 207se directory in your Portfolio1 directory. ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ cd Portfolio1 ]0;flanag20@hvs-its-lnx01: ~/Portfolio1flanag20@hvs-itslnx01:~/Portfolio1$ mkdir 207se Create numbered directories for the labs. i.e. lab1 and lab2 etc. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1flanag20@hvs-itslnx01:~/Portfolio1$ cd 207se ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207seflanag20@hvs-itslnx01:~/Portfolio1/207se$ mkdir lab1 ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207seflanag20@hvs-itslnx01:~/Portfolio1/207se$ mkdir lab2

5 Evidence of transferring lab1 activity into appropriate directory cd lab1 mv ~/Week1.docx./ Evidence of make directory activities using tree.sh tree.sh /home/207se/flanag20. -bin -Portfolio se -----lab lab2 d) Display todays date and using the cal command show the month that you were born. date Tue 28 Feb 16:46:12 GMT cal July 1997 Su Mo Tu We Th Fr Sa e) Move into the lab1 directory and use the appropriate command to show the current directory ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ cd ~/Portfolio1/207se/lab1 ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab1flanag20@hvs-itslnx01:~/Portfolio1/207se/lab1$ pwd /home/207se/flanag20/portfolio1/207se/lab1 f) What is talk, write and wall are for Wall Write a message to all users. Write Send a message to another user. Talk Talk with another user, even across different terminals. g) What command prevents the effects of those three commands from interrupting you.

6 h) Created a file called song.txt and entered a randomly generated song from Using wc count the number of words and lines in the file. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ wc song.txt song.txt Use grep to get the lines containing "and" and the number of the lines contain and in the document. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ grep and song.txt -n Output: Use cat to show the contents of the file. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ cat song.tc[kxt New life through me let me, with all my Soul no matter what they say the best doesn't mean Giving me the way you used to touch me and You'll succeed smile again just smile again just smile again Just smile again I'll always be there for You, gettin' it on the people Looked behind me, givin' it all For me need more and I can't even ask For more 'cause boy, you you are come As you are or where you're from come and Dance to the side, so I wanna Say thank you lord for showing me the way that I played around with love before I Never met no one loves you can Bring the world tonight, said the hearts of Stone, the only one for me Every part of me so baby, Baby the thought of no you cuts just Like yesterday you turned my life is full of Ecstasy where all you need and more and More see I finally know and you dont have to Makes lots of trust, and kissing and Holding you tight letting you know I'll Do what you need I found someone that's promise To be necessary to me I just Wanna be, you're so naughty and nice Hey they think I'm in need of love if I Was just a girl likes me never gonna Settle for less but if you got me coin' Craze boy, you lied you lied, you...

7 Replace any two words with your first and second names, save as song_name.txt. Use an appropriate command to see if and how they differ. differ song.txt song_name.txt 1c1 < New life through me let me, with all my --- > New life through me let Conor, with all my 25c25 < To be necessary to me I just --- > To be necessary to me Flanagan just Use sort to sort the file and redirect the output to a new file called song2.txt ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ sort song.txt > song2.txt Use sort and rev to reverse the sorted contents of song.txt and append the output to song2.txt ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ sort song.txt rev > song2.txt Total memory used and the total memory available ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ free -m total used free shared buff/cache available Mem: Swap: Display Name and Student ID on screen. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ echo Conor Flanagan Conor Flanagan Find out how you can display your username on the screen. ]0;flanag20@hvs-its-lnx01: ~/Portfolio1/207se/lab2flanag20@hvs-itslnx01:~/Portfolio1/207se/lab2$ echo "$USER" flanag20

8 List the processes that are running. ps -a PID TTY TIME CMD pts/82 00:00:00 less pts/70 00:00:00 pico pts/11 00:00:00 nano pts/11 00:00:00 nano pts/82 00:00:11 bochs-bin pts/3 00:00:00 bochs-bin pts/0 00:00:00 bash pts/0 00:00:01 bochs-bin pts/0 00:00:00 bash pts/0 00:00:00 bochs-bin pts/70 00:00:00 pico pts/49 00:00:00 man pts/49 00:00:00 man pts/49 00:00:00 pager pts/20 00:00:00 nano pts/8 00:00:00 pico pts/29 00:00:00 pico pts/67 00:00:00 pico pts/27 00:00:00 vi pts/16 00:00:00 script pts/36 00:00:00 ps pts/79 00:00:00 man pts/79 00:00:00 pager What are the differences between the Linux commands less, more and most. More Splits the output into individual screens which can be continued through using the spacebar. Less Like more, however provides a way to scroll back through previous pages. Most Can display more than one file at a time.

9 Lab Activity 4 Bootloader a) Brief description of the Lab activity and what you did: Booted pragma linux with bochs on the os-207se linux server. Created a bootloader using the helloworld.asm assembly code on moodle as a base. Bootloader (name.asm) displays name, address, favourite second year module, date of birth, age and student ID on separate lines. b) Boot pragma linux with bochs. ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ tar xvfz pragma- 207.tgz pragmalinux-img/ pragmalinux-img/readme pragmalinux-img/bootloader pragmalinux-img/a.img pragmalinux-img/bochsrc pragmalinux-img/bochsrc1 pragmalinux-img/bochsout.txt pragmalinux-img/testform.txt pragmalinux-img/bootloader.asm ]0;flanag20@hvs-its-lnx01: ~flanag20@hvs-its-lnx01:~$ cd pragmalinux-img ]0;flanag20@hvs-its-lnx01: ~/pragmalinux-imgflanag20@hvs-itslnx01:~/pragmalinux-img$ ls a.img bochsout.txt bochsrc bochsrc1 bootloader bootloader.asm README TESTFORM.txt c) Make a bootloader that displays your name, address, your favourite second year module, date of birth, age and student number on separate lines. Source code sensibly commented for your bootloader. (next page)

10 [BITS 16] [ORG 0X7C00] top: mov ax,0x0000 mov ds,ax mov si,name call writestring mov si, call writestring mov si,module call writestring mov si,dob call writestring mov si,age call writestring mov si,sid call writestring jmp $ ;Use writestring to display Name ;Use writestring to display ;Use writestring to display Module ;Use writestring to display Date of Birth ;Use writestring to display Age ;Use writestring to display Student ID writestring: mov ah,0x0e ;Display Character mov bh,0x00 mov bl,0x07 nextchar: lodsb cmp al,0 jz done int 0x10 jmp nextchar done: ret Name db 'Conor Flanagan',13,10,0 db 'flanag20@uni.coventry.ac.uk',13,10,0 Module db '210CT',13,10,0 Dob db '18/07/1997',13,10,0 Age db '19',13,10,0 sid db ' ',13,10,0 times 510-($-$$) db 0 ;Declaring values dw 0xAA55 Output from Bochs showing student details.

11 Lab Activity 6 Memory Management a) Determine. using first-fit, best-fit and worst-fit which unallocated memory blocks the process memory requirements will be allocated to, and prove using the.exe files provided. 1. Processes: Process 1 (300) Process 2 (350) Process 3 (450) Process 4 (400) Process 5 (150) Memory: Block 1 (300) Block 2 (500) Block 3 (250) Block 4 (220) Block 5 (270) First-fit method: Process 1 (300) allocated to Block 1 (300). Process 2 (350) allocated to Block 2 (500). Process 3 (450) cannot be allocated. Process 4 (400) cannot be allocated. Process 5 (150) allocated to Block 3 (250). First-fit.exe output: Results match my own determinations using the first-fit method.

12 2. Best-fit method: Process 1 (300): - Block 1 (300) difference: 0 - Block 2 (500) difference: Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 1 allocated to Block 1. Process 2 (350): - Block 2 (500) difference: Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 2 allocated to Block 2. Process 3 (450): - Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 3 cannot be allocated. Process 4 (400): - Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 4 cannot be allocated. Process 5 (150): - Block 3 (250) difference: Block 4 (220) difference: 70 - Block 5 (270) difference: 120 Process 5 allocated to Block 4. Best-fit.exe output: Results match my own determinations using the best-fit method.

13 3. Worst-fit method: Process 1 (300): - Block 1 (300) difference: 0 - Block 2 (500) difference: Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 1 allocated to Block 2. Process 2 (350): - Block 1 (300) does not fit. - Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 2 cannot be allocated. Process 3 (450): - Block 1 (300) does not fit. - Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 3 cannot be allocated. Process 4 (400): - Block 1 (300) does not fit. - Block 3 (250) does not fit. - Block 4 (220) does not fit. - Block 5 (270) does not fit. Process 4 cannot be allocated. Process 5 (150): - Block 1 (300) difference: Block 3 (250) difference: Block 4 (220) difference: 70 - Block 5 (270) difference: 120 Process 5 allocated to Block 1. Worst-fit.exe output: Results match my own determinations using the Worst-fit method.

14 First-fit and Best-fit allocate the processes with the least fragmentation, both leaving only 2 processes unallocated. b) Use first-in-first-out and random page allocation methods to show how pages will be swapped in and out of main memory for the examples. 1. First-in-first-out: Paging Accessing Sequence: Three table page entries: Page Entry Page Entry Page Entry Page Fault * * * * * * * * Page Fault Total: 8 Fifo.exe returns the same result: Four table page entries: Page Entry Page Entry Page Entry Page Entry Page Fault * * * * * * * * Page Fault Total: 8 Fifo.exe returns the same result:

15 2. Random page allocation: Three table page entries: Page Entry Page Entry Page Entry Page Fault * * * * * * * * * Page Fault Total: 9 Random.exe returns a different result because the victim pages are selected randomly, which can have a positive or negative impact. Four table page entries: Page Entry Page Entry Page Entry Page Entry Page Fault * * * * * * * Page Fault Total: 7 Random.exe returns a different result, again because the victim pages are randomly selected.

16 Lab Activity 7 Buffer a) Brief description of the Buffer Activity. Task is to first comment the buffer C code provided on moodle, then modify it, first to display error messages, then to display total characters read, characters read from the buffer, words in the document and times the buffer was filled. Finally a function added to compare the file with another, and if they are different display how. b) Commented Buffer.c code. #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #define BUF_SIZE 500 //Define buffer size at 500 #define OUTPUT_MODE 0700 //Define file permission int main(int argc, char *argv[]) { int in_fd, out_fd; int rd_size = 1, wr_size; char buf[buf_size]; //Declare buffer if (argc!= 3) exit(1); in_fd = open(argv[1], O_RDONLY); if (in_fd < 0) exit(2); //Open input file out_fd = creat(argv[2],output_mode); //Create output file if (out_fd < 0) exit(3); while (rd_size > 0) { rd_size = read(in_fd, buf,buf_size); //Read from input file to buffer if (rd_size <0) exit(4); wr_size = write(out_fd, buf, rd_size); //Write from buffer to output if (wr_size<=0){ close(in_fd); close(out_fd); //Close input and output exit(5);

17 c) Update the code to so that it prints if an error has occurred or if a file is successfully created with the content of the review in it. #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #define BUF_SIZE 500 //Define buffer size at 500 #define OUTPUT_MODE 0700 //Define file permission int main(int argc, char *argv[]) { int in_fd, out_fd; int rd_size = 1, wr_size; char buf[buf_size]; //Declare buffer if (argc!= 3){ printf("too many or too few arguments.\n"); exit(1); in_fd = open(argv[1], O_RDONLY); //Open input file if (in_fd < 0) { printf("given file is empty.\n"); exit(2); out_fd = creat(argv[2], OUTPUT_MODE); //Create output file if (out_fd < 0) { printf("file not created.\n"); exit(3); while (rd_size > 0) { rd_size = read(in_fd, buf, BUF_SIZE); //Read from input file to buffer if (rd_size <0) { printf("nothing to read from file.\n"); exit(4); wr_size = write(out_fd, buf, rd_size); //Write from buffer to output if (wr_size<=0){ close(in_fd); close(out_fd); exit(5); //Close input and output Contents of hamlet.txt:

18 d) Updated buffer.c code to show how many character are read to buffer, how many character read at a time into the buffer, how many words in the document and how many times the buffer is filled #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #define BUF_SIZE 500 //Define buffer size at 500 #define OUTPUT_MODE 0700 //Define file permission int main(int argc, char *argv[]) { int in_fd, out_fd; int rd_size = 1, wr_size; int characters = 0, filled = 0; int wordcount = 1, loop; char buf[buf_size]; //Declare buffer if (argc!= 3){ printf("too many or too few arguments.\n"); exit(1); in_fd = open(argv[1], O_RDONLY); //Open input file if (in_fd < 0) { printf("given file is empty.\n"); exit(2); out_fd = creat(argv[2], OUTPUT_MODE); //Create output file if (out_fd < 0) { printf("file not created.\n"); exit(3); while (rd_size > 0) { rd_size = read(in_fd, buf, BUF_SIZE); //Read from input file to buffer if (rd_size <0) { printf("nothing to read from file.\n"); exit(4); if (rd_size==500) { //If rd_size is 500 characters = characters + 500; //Add 500 to char count filled = filled + 1; //Add 1 filled buffer else{ characters = characters + rd_size; //Else add rd_size to char count for (loop = 0; loop < rd_size; loop++){ if (buf[loop] == ' '){ //If char is space add to word count wordcount = wordcount + 1; else if (buf[loop] == '.'){ //If char is space add to word count wordcount = wordcount + 1; loop = loop + 1; //Next char likely ' ' so skip wr_size = write(out_fd, buf, rd_size); //Write from buffer to output if (wr_size<=0){ close(in_fd); close(out_fd); //Close input and output printf("character count: %d\n", characters); printf("word count: %d\n", wordcount); printf("buffers filled: %d\n", filled); exit(5);

19 Output of updated code: e) Alter buffer size and explain how this influences the number of times the buffer is filled. When the buffer size is increased, the buffer is filled less often. This means there is less of an overhead when filling the buffer and so the operation takes less time. f) Adapt the code in buffer.c so it is possible to compare two files and determine if they are the same. If they are different explain how they differ. #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #define BUF_SIZE 500 //Define buffer size at 500 #define OUTPUT_MODE 0700 //Define file permission int compare(char *File) //Compare with another file { int in0fd, in1fd; char comparefile[50]; int rd_size0 = 1, rd_size1 = 2; char buf0[buf_size], buf1[buf_size]; int loop, bool=0; char q; printf("file to compare? "); //Ask for second filename scanf("%s", comparefile); in0fd = open(comparefile, O_RDONLY); in1fd = open(file, O_RDONLY); if (in0fd<0) { printf("given file is empty.\n"); //Exit if file is empty exit(6); while (rd_size0 > 0) { rd_size0 = read(in0fd, buf0, BUF_SIZE); //Read each file rd_size1 = read(in1fd, buf1, BUF_SIZE); //into each buffer if (rd_size0 <0) { printf("nothing to read from file.\n"); exit(4); if (rd_size1 <0) { printf("nothing to read from file.\n"); exit(4); for (loop = 0; loop < rd_size0; loop++) { q = buf1[loop]; if (buf0[loop]!= q) { //Compares characters in each buffer if (bool == 0) printf("file differs with characters: \n"); printf("%c", q); //Prints characters that differ

20 bool = 1; printf("\n"); if (bool == 0) //Declare if files are identical printf("files are the same.\n"); int main(int argc, char *argv[]) { int in_fd, out_fd; int rd_size = 1, wr_size; int characters = 0, filled = 0; int wordcount = 1, loop; char buf[buf_size]; //Declare buffer char cmpr[1]; if (argc!= 3){ printf("too many or too few arguments.\n"); exit(1); in_fd = open(argv[1], O_RDONLY); //Open input file if (in_fd < 0) { printf("given file is empty.\n"); exit(2); out_fd = creat(argv[2], OUTPUT_MODE); //Create output file if (out_fd < 0) { printf("file not created.\n"); exit(3); while (rd_size > 0) { rd_size = read(in_fd, buf, BUF_SIZE); //Read from input file to buffer if (rd_size <0) { printf("nothing to read from file.\n"); exit(4); if (rd_size==buf_size) { //If rd_size is 500 characters = characters + BUF_SIZE; //Add 500 to char count filled = filled + 1; //Add 1 filled buffer else{ characters = characters + rd_size; //Else add rd_size to char count for (loop = 0; loop < rd_size; loop++){ if (buf[loop] == ' '){ //If char is space add to word count wordcount = wordcount + 1; else if (buf[loop] == '.'){ //If char is space add to word count wordcount = wordcount + 1; loop = loop + 1; //Next char likely ' ' so skip wr_size = write(out_fd, buf, rd_size); //Write from buffer to output if (wr_size<=0){ close(in_fd); close(out_fd); //Close input and output printf("character count: %d\n", characters); printf("word count: %d\n", wordcount); printf("buffers filled: %d\n", filled); printf("compare file with another [yes/no]? "); scanf("%s", cmpr); if (cmpr[0]=='y'){ compare(argv[2]); exit(5);

21 Comparison of review.txt and hamlet.txt Comparison of hamlet.txt and review_observer.txt

22 Lab Activity 8 Cache Buffer a) Brief Description of Cache Buffer Activity. Alter the cache-buffer file provided so that it outputs the bytes to the screen, then alter further to prove that the output is being buffered, and display statistics including byte count and buffer count. b) Commented implementation of the cr_read_byte function. char cr_read_byte(cr_file* f){ char curbyte; //Character for current byte if (f->usedbuffer >= f->bufferlength){ refill(f); //If buffer is empty refill else{ curbyte = f->buffer[f->usedbuffer]; //Assigns current byte to character f->usedbuffer += 1; //Increases buffer pointer by 1. return curbyte; //Returns current byte character return EOF; Output (some file text cropped to the side for visibility): Explanation: Checks if the usedbuffer pointer is past the end of the buffer length. If so, calls the refill function to refill the buffer and reset the usedbuffer pointer. If not, increases the pointer by 1 and returns the byte the pointer was at. Char variable is used so that the pointer can be increased before the return statement without returning the incorrect (the next) byte.

23 c) Additional tasks 1 and 2: Prove the file output is being buffered, and provide statistics for bytes read in total and times buffer was refilled. Declaration line added to cache_reader.h library: int totalbytes; //Stores total amount of bytes from file cache_reader.c with changes highlighted: #include "cache_reader.h" int refill(cr_file* buff){ //Refills a buffer //Only works when completely used buffer if(buff->usedbuffer!=buff->bufferlength) return 0; else{ buff->usedbuffer=0; int len=fread(buff->buffer, sizeof(char), buff->bufferlength, buff->file); //If we didn't fill the buffer, fill up with EOF if(len<buff->bufferlength) for(int i=len;i<buff->bufferlength;i++) buff->buffer[i]=eof; //Accessing like an array! buff->totalbytes += len; //Add len to total byte count return len; void cr_close(cr_file* f){ free(f->buffer); fclose(f->file); cr_file* cr_open(char * filename, int buffersize){ //Info on malloc // FILE* f; if ((f = fopen(filename, "r")) == NULL){ fprintf(stderr, "Cannot open %s\n", filename); return 0; cr_file* a=(cr_file*)malloc(sizeof(cr_file)); a->file=f; a->bufferlength=buffersize; a->usedbuffer=buffersize; //Start off with no characters, so refill will work as expected a->buffer=(char*)malloc(sizeof(char)*buffersize); a->totalbytes=0; //Start byte total at 0 refill(a); return a; // char cr_read_byte(cr_file* f){ char curbyte; //Character for current byte if (f->usedbuffer >= f->bufferlength){ printf("\n"); //Separates each buffer refill to individual lines refill(f); //If buffer is empty refill else{ curbyte = f->buffer[f->usedbuffer]; //Assigns current byte to character f->usedbuffer += 1; //Increases buffer pointer by 1. return curbyte; //Returns current byte character return EOF;

24 cache_example.c with changes highlighted: #include "cache_reader.h" //Simple file display to show how easy it is to use the cached reader functions int main(){ char c; //Open a file cr_file* f = cr_open("text",20); //While there are useful bytes coming from it while((c=cr_read_byte(f))!=eof) //Print them printf("%c",c); //Then close the file printf("\ntotal Bytes: %d",f->totalbytes); //Prints total byte count. printf("\ntotal Refills: %d",f->totalbytes/f->bufferlength); //Prints total number of refills performed. printf( \n ); cr_close(f); //And finish return 0; Output:

25 Lab 10: The Cache Buffer from week 8 with system calls a) Brief description of the activity Change cache_reader.h library from using fopen, fread and fclose functions to use the system call versions (open, read, close). Also remove effects of caching on the library. b) Changes the cache_reader library from using the fopen, fread, fclose functions to the system call versions open, read, close. #include "cache_reader.h" #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int refill(cr_file* buff){ //Refills a buffer //Only works when completely used buffer if(buff->usedbuffer!=buff->bufferlength) return 0; else{ buff->usedbuffer=0; int len=read(buff->file, buff->buffer, buff->bufferlength); //If we didn't fill the buffer, fill up with EOF if(len<buff->bufferlength) for(int i=len;i<buff->bufferlength;i++) buff->buffer[i]=eof; //Accessing like an array! buff->totalbytes += len; //Add len to total byte count return len; void cr_close(cr_file* f){ free(f->buffer); close(f->file); cr_file* cr_open(char * filename, int buffersize){ FILE* f; if ((f = open(filename, O_RDONLY)) < 0){ //Changed == NULL to < 0 fprintf(stderr, "Cannot open %s\n", filename); return 0; cr_file* a=(cr_file*)malloc(sizeof(cr_file)); a->file=f; a->bufferlength=buffersize; a->usedbuffer=buffersize; //Start off with no characters, so refill will work as expected a->buffer=(char*)malloc(sizeof(char)*buffersize); a->totalbytes=0; //Start byte total at 0 refill(a); return a; No changes were made to cache_reader.h Output is the same as running previously. Screenshot on next page.

26 c) Changes cache_reader library to remove (as far as possible) the effects of caching on the library. References D. Gelernter, ComputerWorld (2003) Future of operating systems: simplicity [online] available from < R. Rosini, Medium (2016) AI and the Future of Operating Systems [online] available from

Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel

Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel 1 File System Why files? 1. Storing a large amount of data 2. Long-term data retention 3. Access to the various processes in parallel 2 Basic Terms File Structures Field basic unit of data. Contains single

More information

12: Filesystems: The User View

12: Filesystems: The User View 12: Filesystems: The User View Mark Handley Goals for Long-term Information Storage 1. Store large amounts of data. 2. Information stored must survive the termination of the process using it and reboot

More information

Unix Basics Compiling and Using. CMPT 300 Operating Systems I Summer Segment 2: Unix Basics. Melissa O Neill

Unix Basics Compiling and Using. CMPT 300 Operating Systems I Summer Segment 2: Unix Basics. Melissa O Neill CMPT 300 Operating Systems I Summer 1999 Segment 2: Unix Basics Melissa O Neill Unix Basics Compiling and Using You had to learn how to do the basics on a Unix system, including: Look up a manual page

More information

CS Operating Systems Lab 3: UNIX Processes

CS Operating Systems Lab 3: UNIX Processes CS 346 - Operating Systems Lab 3: UNIX Processes Due: February 15 Purpose: In this lab you will become familiar with UNIX processes. In particular you will examine processes with the ps command and terminate

More information

Exercise 1: Basic Tools

Exercise 1: Basic Tools Exercise 1: Basic Tools This exercise is created so everybody can learn the basic tools we will use during this course. It is really more like a tutorial than an exercise and, you are not required to submit

More information

The Unix Shell & Shell Scripts

The Unix Shell & Shell Scripts The Unix Shell & Shell Scripts You should do steps 1 to 7 before going to the lab. Use the Linux system you installed in the previous lab. In the lab do step 8, the TA may give you additional exercises

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page   and visit the COL100 course page. COL100 Lab 2 I semester 2017-18 Week 2, 2017 Objective More familiarisation with Linux and its standard commands Part 1 1. Login to your system and open a terminal window. 2. Open the web-browser and visit

More information

A: We see the ps auxw execute and print on screen. The program holds the command in buffer then it is printed on screen.

A: We see the ps auxw execute and print on screen. The program holds the command in buffer then it is printed on screen. Brian Duenas CSE 460 Lab 4 20 points Total 2. Process Pipes Q: What do you see when you execute "pipe1"? Why? We see the ps auxw execute and print on screen. The program holds the command in buffer then

More information

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes CSci 4061 Introduction to Operating Systems IPC: Basics, Pipes Today Directory wrap-up Communication/IPC Test in one week Communication Abstraction: conduit for data exchange between two or more processes

More information

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP Unix Guide Meher Krishna Patel Created on : Octorber, 2017 Last updated : December, 2017 More documents are freely available at PythonDSP Table of contents Table of contents i 1 Unix commands 1 1.1 Unix

More information

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment. Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special

More information

Today s Learning Objectives

Today s Learning Objectives Today s Learning Objectives 15-123 Systems Skills in C and Unix We will Review ints and modular arithmetic Learn basic Data types and Formats How Conditionals and loops work How Arrays are defined, accessed,

More information

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one] Data and Computer Security (CMPD414) Lab II Topics: secure login, moving into HOME-directory, navigation on Unix, basic commands for vi, Message Digest This lab exercise is to be submitted at the end of

More information

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID: Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering Final Exam Name: This exam is open book and notes. Read the questions carefully and focus your answers on what has been

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the

More information

Project 2: Shell with History1

Project 2: Shell with History1 Project 2: Shell with History1 See course webpage for due date. Submit deliverables to CourSys: https://courses.cs.sfu.ca/ Late penalty is 10% per calendar day (each 0 to 24 hour period past due). Maximum

More information

File Systems. Information Server 1. Content. Motivation. Motivation. File Systems. File Systems. Files

File Systems. Information Server 1. Content. Motivation. Motivation. File Systems. File Systems. Files Content File Systems Hengming Zou, Ph.D. Files Disk scheduling, file structure, indexed files Directories File system implementation File system performance Example file systems 2006-4-29 1 2006-4-29 2

More information

CS 460 Linux Tutorial

CS 460 Linux Tutorial CS 460 Linux Tutorial http://ryanstutorials.net/linuxtutorial/cheatsheet.php # Change directory to your home directory. # Remember, ~ means your home directory cd ~ # Check to see your current working

More information

Strategy for developing efficient programs:

Strategy for developing efficient programs: Strategy for developing efficient programs: 1. Design the program well 2. Implement the program well** 3. Test the program well 4. Only after you re sure it s working, measure performance 5. If (and only

More information

Problem Set 1: Unix Commands 1

Problem Set 1: Unix Commands 1 Problem Set 1: Unix Commands 1 WARNING: IF YOU DO NOT FIND THIS PROBLEM SET TRIVIAL, I WOULD NOT RECOMMEND YOU TAKE THIS OFFERING OF 300 AS YOU DO NOT POSSESS THE REQUISITE BACKGROUND TO PASS THE COURSE.

More information

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (( )) (( )) [ x x ] cdc communications, inc. [ x x ] \ / presents... \ / (` ') (` ') (U) (U) Gibe's UNIX COMMAND Bible ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The latest file from the Cow's

More information

COMP s1 Lecture 1

COMP s1 Lecture 1 COMP1511 18s1 Lecture 1 1 Numbers In, Numbers Out Andrew Bennett more printf variables scanf 2 Before we begin introduce yourself to the person sitting next to you why did

More information

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set

More information

Software I: Utilities and Internals. What isbash?

Software I: Utilities and Internals. What isbash? Software I: Utilities and Internals Lecture 6 Using The Shell What isbash? bash (Bourne Again Shell) is designed as a free replacement of the Bourne shell (the original UNIX shell) to be bundled with Linux.

More information

CSCI 2132 Final Exam Solutions

CSCI 2132 Final Exam Solutions Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question

More information

Laboratory 1 Semester 1 11/12

Laboratory 1 Semester 1 11/12 CS2106 National University of Singapore School of Computing Laboratory 1 Semester 1 11/12 MATRICULATION NUMBER: In this lab exercise, you will get familiarize with some basic UNIX commands, editing and

More information

Operating systems. Lecture 7

Operating systems. Lecture 7 Operating systems. Lecture 7 Michał Goliński 2018-11-13 Introduction Recall Plan for today History of C/C++ Compiler on the command line Automating builds with make CPU protection rings system calls pointers

More information

Linux Shell Script. J. K. Mandal

Linux Shell Script. J. K. Mandal Linux Shell Script J. K. Mandal Professor, Department of Computer Science & Engineering, Faculty of Engineering, Technology & Management University of Kalyani Kalyani, Nadia, West Bengal E-mail: jkmandal@klyuniv.ac.in,

More information

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions:

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions: Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application Questions: Q.1 Check the output of the following commands:date, ls, who, cal, ps, wc, cat,

More information

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am) Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L0101 (10:10-11:00am) Do not turn this page until you have received the signal to start.

More information

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018 Total Points: 100 COP4342 UNIX Tools Assignment #3: A Simple Unix Shell Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018 Description: The bash shell utility on UNIX and

More information

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2 OS COMPONENTS OVERVIEW OF UNIX FILE I/O CS124 Operating Systems Fall 2017-2018, Lecture 2 2 Operating System Components (1) Common components of operating systems: Users: Want to solve problems by using

More information

518 Lecture Notes Week 3

518 Lecture Notes Week 3 518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management

More information

Lecture 7: file I/O, more Unix

Lecture 7: file I/O, more Unix CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 7: file

More information

LOG ON TO LINUX AND LOG OFF

LOG ON TO LINUX AND LOG OFF EXPNO:1A LOG ON TO LINUX AND LOG OFF AIM: To know how to logon to Linux and logoff. PROCEDURE: Logon: To logon to the Linux system, we have to enter the correct username and password details, when asked,

More information

Naked C Lecture 6. File Operations and System Calls

Naked C Lecture 6. File Operations and System Calls Naked C Lecture 6 File Operations and System Calls 20 August 2012 Libc and Linking Libc is the standard C library Provides most of the basic functionality that we've been using String functions, fork,

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

Introduction to Supercomputing

Introduction to Supercomputing Introduction to Supercomputing TMA4280 Introduction to UNIX environment and tools 0.1 Getting started with the environment and the bash shell interpreter Desktop computers are usually operated from a graphical

More information

CSE 303 Midterm Exam

CSE 303 Midterm Exam CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

M.CS201 Programming language

M.CS201 Programming language Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct

More information

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments File I/O Content Input Output Devices File access Function of File I/O Redirection Command-line arguments UNIX and C language C is a general-purpose, high-level language that was originally developed by

More information

Recitation 2/18/2012

Recitation 2/18/2012 15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator

More information

Introduction to Linux

Introduction to Linux Introduction to Linux University of Bristol - Advance Computing Research Centre 1 / 47 Operating Systems Program running all the time Interfaces between other programs and hardware Provides abstractions

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight HW2 Due Thursday, July 19 th Midterm on Monday, July 23 th 10:50-11:50 in TBD (And regular exercises in between) POSIX

More information

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. 2 Conventions Used in This Book p. 2 Introduction to UNIX p. 5 An Overview

More information

PROCESSES. Jo, Heeseung

PROCESSES. Jo, Heeseung PROCESSES Jo, Heeseung TODAY'S TOPICS What is the process? How to implement processes? Inter-Process Communication (IPC) 2 WHAT IS THE PROCESS? Program? vs. Process? vs. Processor? 3 PROCESS CONCEPT (1)

More information

Processes. Jo, Heeseung

Processes. Jo, Heeseung Processes Jo, Heeseung Today's Topics What is the process? How to implement processes? Inter-Process Communication (IPC) 2 What Is The Process? Program? vs. Process? vs. Processor? 3 Process Concept (1)

More information

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls 1 Unix File I/O 2 Unix System Calls System calls are low level functions the operating system makes available to applications

More information

Getting your department account

Getting your department account 02/11/2013 11:35 AM Getting your department account The instructions are at Creating a CS account 02/11/2013 11:36 AM Getting help Vijay Adusumalli will be in the CS majors lab in the basement of the Love

More information

Pipes. Pipes Implement a FIFO. Pipes (cont d) SWE 545. Pipes. A FIFO (First In, First Out) buffer is like a. Pipes are uni-directional

Pipes. Pipes Implement a FIFO. Pipes (cont d) SWE 545. Pipes. A FIFO (First In, First Out) buffer is like a. Pipes are uni-directional Pipes SWE 545 Pipes Pipes are a way to allow processes to communicate with each other Pipes implement one form of IPC (Interprocess Communication) This allows synchronization of process execution There

More information

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison

More information

CPS 310 first midterm exam, 10/6/2014

CPS 310 first midterm exam, 10/6/2014 CPS 310 first midterm exam, 10/6/2014 Your name please: Part 1. More fun with fork and exec* What is the output generated by this program? Please assume that each executed print statement completes, e.g.,

More information

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen Working With Unix Scott A. Handley* September 15, 2014 *Adapted from UNIX introduction material created by Dr. Julian Catchen What is UNIX? An operating system (OS) Designed to be multiuser and multitasking

More information

System Programming. Introduction to Unix

System Programming. Introduction to Unix Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Introduction

More information

Computer Programming Lecture 1 이윤진서울대학교

Computer Programming Lecture 1 이윤진서울대학교 Computer Programming Lecture 1 이윤진서울대학교 2007.12.20. Slide Credits 엄현상교수님 서울대학교컴퓨터공학부 Computer Programming, g, 2007 봄학기 순서 강의소개 강의목표 강의개요 수업진행방법및평가 UNIX/LINUX 기초 주요기능 주요기능 파일시스템 강의목표 Unix/Linux 중심의프로그래밍

More information

2009 S2 COMP File Operations

2009 S2 COMP File Operations 2009 S2 COMP1921 9. File Operations Oliver Diessel odiessel@cse.unsw.edu.au Last updated: 16:00 22 Sep 2009 9. File Operations Topics to be covered: Streams Text file operations Binary file operations

More information

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018 FILE SYSTEMS Tanzir Ahmed CSCE 313 Fall 2018 References Previous offerings of the same course by Prof Tyagi and Bettati Textbook: Operating System Principles and Practice 2 The UNIX File System File Systems

More information

Unix Introduction to UNIX

Unix Introduction to UNIX Unix Introduction to UNIX Get Started Introduction The UNIX operating system Set of programs that act as a link between the computer and the user. Developed in 1969 by a group of AT&T employees Various

More information

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Shells and Files CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Shells Command and scripting languages for Unix First shell: Thompson shell sh, developed

More information

Section 1: C Programming Lab

Section 1: C Programming Lab Course Code : MCSL-017 Course Title : C and Assembly Language Programming (Lab Course) Assignment Number : MCA(1)/015/Assignment/17-18 Maximum Marks : 100 Weightage : 25% Last Dates for Submission : 15th

More information

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018.

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018. Preview Process Control What is process? Process identifier A key concept in OS is the process Process a program in execution Once a process is created, OS not only reserve space (in Memory) for the process

More information

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry Intro to Linux and C CSCI 2400/ ECE 3217: Computer Architecture Instructors: David Ferry 1 Overview Linux C Hello program in C Compiling 2 History of Linux Way back in the day: Bell Labs Unix Widely available

More information

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines Introduction to UNIX Logging in Basic system architecture Getting help Intro to shell (tcsh) Basic UNIX File Maintenance Intro to emacs I/O Redirection Shell scripts Logging in most systems have graphical

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm CSE333 SECTION 5 Important Dates October 27 th Homework 2 Due October 29 th Midterm String API vs. Byte API Recall: Strings are character arrays terminated by \0 The String API (functions that start with

More information

CSC 1600 Unix Processes. Goals of This Lecture

CSC 1600 Unix Processes. Goals of This Lecture CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process

More information

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages ULI101 Week 02 Week Overview Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages Text editing Common file utilities: cat,more,less,touch,file,find

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 15: Unix interface: low-level interface Cristina Nita-Rotaru Lecture 15/Fall 2013 1 Streams Recap Higher-level interface, layered on top of the primitive file descriptor

More information

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT Unix as a Platform Exercises + Solutions Course Code: OS 01 UNXPLAT Working with Unix Most if not all of these will require some investigation in the man pages. That's the idea, to get them used to looking

More information

Homework 4 Answers. Due Date: Monday, May 27, 2002, at 11:59PM Points: 100. /* * macros */ #define SZBUFFER 1024 /* max length of input buffer */

Homework 4 Answers. Due Date: Monday, May 27, 2002, at 11:59PM Points: 100. /* * macros */ #define SZBUFFER 1024 /* max length of input buffer */ Homework 4 Answers Due Date: Monday, May 27, 2002, at 11:59PM Points: 100 UNIX System 1. (10 points) How do I delete the file i? Answer: Either rm./-i or rm -- -i will work. 2. (15 points) Please list

More information

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

CSCI-E28 LECTURE 2 SAMPLES PAGE 1

CSCI-E28 LECTURE 2 SAMPLES PAGE 1 CSCI-E28 LECTURE 2 SAMPLES PAGE 1 :::::::::::::: who0.c :::::::::::::: * who version 0 * main outline but no substance main() int fd; for file des of utmp struct utmp current_record; hold info from file

More information

CS240: Programming in C. Lecture 14: Errors

CS240: Programming in C. Lecture 14: Errors CS240: Programming in C Lecture 14: Errors Errors We ve already seen a number of instances where unexpected (and uncaught) errors can take place: Memory buffer overflow/underflow unintended casts misuse

More information

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management To do q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

UNIX System Programming

UNIX System Programming File I/O 경희대학교컴퓨터공학과 조진성 UNIX System Programming File in UNIX n Unified interface for all I/Os in UNIX ü Regular(normal) files in file system ü Special files for devices terminal, keyboard, mouse, tape,

More information

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze EECS 2031 Software Tools Prof. Mokhtar Aboelaze Footer Text 1 EECS 2031E Instructor: Mokhtar Aboelaze Room 2026 CSEB lastname@cse.yorku.ca x40607 Office hours TTH 12:00-3:00 or by appointment 1 Grading

More information

Chapter-3. Introduction to Unix: Fundamental Commands

Chapter-3. Introduction to Unix: Fundamental Commands Chapter-3 Introduction to Unix: Fundamental Commands What You Will Learn The fundamental commands of the Unix operating system. Everything told for Unix here is applicable to the Linux operating system

More information

CSE 410: Systems Programming

CSE 410: Systems Programming CSE 410: Systems Programming Input and Output Ethan Blanton Department of Computer Science and Engineering University at Buffalo I/O Kernel Services We have seen some text I/O using the C Standard Library.

More information

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w Preview Interprocess Communication with Pipe Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w COCS 350 System Software, Fall 2015 1 Interprocess Communication

More information

Introduction to Linux. Roman Cheplyaka

Introduction to Linux. Roman Cheplyaka Introduction to Linux Roman Cheplyaka Generic commands, files, directories What am I running? ngsuser@ubuntu:~$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

Introduction to UNIX Command Line

Introduction to UNIX Command Line Introduction to UNIX Command Line Files and directories Some useful commands (echo, cat, grep, find, diff, tar) Redirection Pipes Variables Background processes Remote connections (e.g. ssh, curl) Scripts

More information

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions Lanka Education and Research Network Linux Architecture, Linux File System, Linux Basic Commands 28 th November 2016 Dilum Samarasinhe () Overview History of Linux Linux Architecture Linux File System

More information

Shell Programming (Part 2)

Shell Programming (Part 2) i i Systems and Internet Infrastructure Security Institute for Networking and Security Research Department of Computer Science and Engineering Pennsylvania State University, University Park, PA Shell Programming

More information

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 Homework 5 Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 UNIX System 1. (10 points) I want to make the file libprog.a in my home directory available to everyone so

More information

Operating systems Portfolio

Operating systems Portfolio Operating systems Portfolio Thebault Yann Student number : 10004434 CE0100-3 Operating systems! Friday 26 November 2010 WEEK 1 6. How does the distinction between supervisor mode and user mode function

More information

Due: February 26, 2014, 7.30 PM

Due: February 26, 2014, 7.30 PM Jackson State University Department of Computer Science CSC 438-01/539-01 Systems and Software Security, Spring 2014 Instructor: Dr. Natarajan Meghanathan Project 1: Exploring UNIX Access Control in a

More information

Xosdev Chapter 1 [The Bootloader] by mr. xsism

Xosdev Chapter 1 [The Bootloader] by mr. xsism Xosdev Chapter 1 [The Bootloader] by mr. xsism Planning/Setting goals When coding an Operating systtem or even a simple kernel you usually start with a bootloader. But what is a bootloader? A bootloader

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r 1. Which symbol will be used with grep command to match the pattern pat at the beginning of a line? A) ^pat B) $pat C) pat$ D) pat^ 2. Which command is used to sort the lines of data in a file in reverse

More information

Introduction to Linux

Introduction to Linux Introduction to Linux Mukesh Pund Principal Scientist, NISCAIR, New Delhi, India History In 1969, a team of developers developed a new operating system called Unix which was written using C Linus Torvalds,

More information

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so!

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Command-line interpreters

Command-line interpreters Command-line interpreters shell Wiki: A command-line interface (CLI) is a means of interaction with a computer program where the user (or client) issues commands to the program in the form of successive

More information