|
Lab 9 (Chapter 9)
Learning Objectives
Lab WorkIn this lab, you will practice the basic file related commands in UNIX. For this purpose, you will make a few files and use then in this and some of the subsequent chapters.
FirstName LastName Major GPA Email Phone Here is the minimum amount of data that you will have in this file. John Doe ECE 3.54 doe@jd.home.org 111.222.3333 James Davis ECE 3.71 davis@jd.work.org 111.222.1111 Al Davis CS 2.63 davis@a.lakers.org 111.222.2222 Ahmad Rashid MBA 3.04 ahmad@mba.org 111.222.4444 Sam Chu ECE 3.68 chu@sam.ab.com 111.222.5555 Arun Roy SS 3.86 roy@ss.arts.edu 111.222.8888 Rick Marsh CS 2.34 marsh@a.b.org 111.222.6666 James Adam CS 2.77 jadam@a.b.org 111.222.7777 Art Pohm ECE 4.00 pohm@ap.a.org 111.222.9999 John Clark ECE 2.68 clark@xyz.ab.com 111.111.5555 Nabeel Ali EE 3.56 ali@ee.eng.edu 111.111.8888 Tom Nelson ECE 3.81 nelson@tn.abc.org 111.111.6666 Pat King SS 3.77 king@pk.xyz.org 111.111.7777 Jake Zulu CS 3.00 zulu@jz.sa.org 111.111.9999 John Lee EE 3.64 jlee@j.lee.com 111.111.2222 Sunil Raj ECE 3.86 raj@sr.cs.edu 111.111.3333 Charles Right EECS 3.31 right@cr.abc.edu 111.111.4444 Diane Rover ECE 3.87 rover@dr.xyz.edu 111.111.5555 Aziz Inan EECS 3.75 ainan@ai.abc.edu 111.111.1111
#include <stdio.h>
main() { int i;
i = 0; sleep(10); while (i < 5) { system("date"); sleep(5); i++; } while (1) { system("date"); sleep(10); } } Now run the following commands, in this order. The first command produces the executable code for the C program in the generate file. The second command appends the output of the date command to the contents of dataFile, initially every five seconds and then every 10 seconds. Note down the number in brackets that the system displays after you have submitted the second command to the system. The tail –f dataFile command displays the current contents of dataFile and then displays the data newly appended to dataFile. gcc ch9.c –o generate generate >> dataFile & tail –f dataFile After you have seen the working the tail –f command for a minute or so, terminate it with <Ctrl-C> and terminate the generate command by using the kill –9 12345, where 12345 is the number that you noted down above after submitting the generate command to the system. Use the tail dataFile command to see the data that was appended to the file. Show your session.
8. Display the sizes of smallFile, mediumFile, largeFile, and /tmp/newDataFile in byes, words, and lines. The size of smallFile and /tmp/newDataFile should be the same. Can you use another command to show the size of the file in bytes? What is it? Show your session.
9. Reproduce the sessions described in sections 9.6 and 9.7 (pp. 232-236). Show results of all the steps involved in these sessions. Show your session.
10. Print two copies of smallFile with line numbers and a header at the top. What command did you use? Could you have used another command to accomplish the same task? Show your session below.
11. Log out.
|
Back to
CS140U Homepage |