Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Assignment

1) Say you are really low on disk space on openlab, and you have some utility programs in C that you like to use often, but you don't have enough disk space to keep the compiled executables around all the time. Each program consists of just one .c file. However, you don't want to manually re-compile each C program each time you want to use it.

Write a short shell script called "C-interp" which is intended to have soft links point at it, and pretends to be a C language interpreter. That is, if you have C file "foo.c", then you would make a link "ln -s C-interp foo". Then, what C-interp does, when called as "foo", is compile "foo.c" and run the resulting executable on the arguments given to "foo". (You can test it on your solutions to the other questions in this assignment.)

Some caveats:

- delete ALL temporary files generated, inculding the executable after it's been executed.

- To ensure you don't delete any files that exist before you start whose names may conflict with the temporary filenames you choose, put *all* temporary files (including the executable) in /tmp/DDD where DDD is a random directory name (doesn't need to be 3 characters). Be sure to remove the directory after C-interp finishes.

- the executable should be called with argv[0] equal to the basename of the .c file, without the '.c', eg "foo.c" gets called as "foo" (but the path can [and should!] be different, so the compiled executable should be in a temporary directory).

- to ensure that your executable name doesn't conflict with other users, you should put the executable in a uniquely-named subdirectory of /tmp.  In fact, it would be best if all your temp files went into this directory, as long as the entire directory is removed when the executable is finished.

- ensure that the temporary files are deleted even if the program is interrupted. ie, use the "trap" command in the Bourne shell to trap signals 0 (Exit), 1 (Hangup), 2 (Interrupt) ,3 (Quit), and 15 (Terminate).

See signal(5) for a list and more details about signals.

2) Write a filter in C that prints M lines out of every N. It can be done using the shell and awk (see ~wayne/pub/ics54). It's more simple and efficient in C. The program's name is "every". It is called like this:

$ every [-N,M] []

where N and M are both positive integers, M <= N. (Anything in square brackets '[]' is optional, and doesn't need to appear on the command line. This is standard for Unix manual pages.) The option argument, if present, must come before any filenames. If no "-N,M" option is on the command line, then "every" should look for an environment variable called EVERY and take its options from there, in the same format as the command line. If "every" can't find options either on the command line or in the environment variable EVERY, then the default is "-1,1". That is, with no options, "every" acts just like cat(1). For example, if we number lines starting at 0, then $ every -10,2 foo.c prints out the following lines of foo.c: 0,1, 10,11, 20,21, 30,31, etc. If M is omitted, eg $ every -10 foo.c then it defaults to 1. (If either N or M is specified on the command line, the environment variable EVERY should be ignored.) If multiple files are given on the command line, each one should be handled INDEPENDENTLY, so "-10,2" means lines 0,1,10,11, etc. of each file.

3) Re-write lss in C. (This is the last time you'll see "lss", I promise.) You may use the standard I/O library; you don't need to restrict yourself to Unix system calls like read(2) and write(2), although you will still need to use SOME Unix system calls, like stat(2).

You may not use any shells directly or indirectly. (For example, you can't use system(3s).)

There are two versions of this program; an easier one, and a harder one. The easier one is described first, and will get you at most 30 marks.

For 30 marks, it doesn't need to support any options, it doesn't need to take any filenames, it doesn't need to print a "total" line, and it doesn't need to do anything special with symbolic links or special files (like the ones found in /dev). However, if a link points nowhere, an appropriate error message should be output, using perror(3c). This is different than what "ls -L" does; that's OK. It does not ignore files whose names begin with '.'. It needs to work correctly for directories and regular files (S_IFDIR and S_IFREG in stat(5), respectively). In other words, in a directory that contains only other directories, regular files, and symbolic links, the output should look just like $ /bin/ls -Lla | grep -v '^total' | sort -k 5nr except symbolic links that point nowhere should cause an error. (The -L makes it easier for you: you only need to use stat(2), rather than *both* lstat(2) and stat(2).)

In addition to the standard C I/O library, you should read the following manual pages: stat(2), stat(5), opendir(3c), readdir(3c), closedir(3c), dirent(4), qsort(3c), getpwuid(3c), perror(3c), time(2), readlink(3c), ctime(3c). You MUST use qsort(3c) to do the sort. You MUST check the return values of *all* system calls and standard I/O functions for errors, and use perror(3c) to print the error. The time should be printed by clipping characters 4 through 15 of the string returned by ctime(3c) (ie., don't do anything fancy for files older than 1 year, like ls(1) does.)

Extra: (these are not bonus marks; this question is out of 40, but you may choose to implement the subset above, and if you do it correctly, it's worth 30 marks out of 40). Implement a more full version of lss that takes filenames and options as arguments. It supports the options -a, -A, and -L in standard Unix format like "-a -L" or "-La" (see getopt(3c)). It needs to handle symbolic links just like "ls -l" does (ie, you'll need to use lstat(2) by default and print where symlinks point, but if "-L" is specified and the file is a symlink then call stat(2).) Finally, if a file explicitly listed on the command line is actually a directory, then it descends the directory just like ls(1) does. No "total" line is necessary.

Attachment:- Assignment File.rar

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92306139
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in Computer Engineering

An exam has 5 multiple choice questions with 2 possible

An exam has 5 multiple choice questions with 2 possible answers each, and 5 true and false questions. Assume each question on the test counts 10 points, and that each question has a unique answer. If a student guesses ea ...

Question suppose that new more powerful arithmetic

Question : Suppose that new, more powerful arithmetic instruction are added to the instruction set. On average, through the use of these more powerful arithmetic instructions, we can reduce the number of arithmetic instr ...

This is sports data analysis with python classone way to

This is sports data analysis with python class. One way to judge a basketball lineup is to determine the point differential when that particular combination of players is in the game - in other words, how many points doe ...

Determine whether or not the following claim is true for

Determine whether or not the following claim is true for all regular expressions r 1  and r 2 . The symbol ≡ stands for equivalence regular expressions in the sense that both expressions denote the same language.  (a) (r ...

Starting out with cpp 8th edition pg 449 7 with

Starting out with Cpp 8th edition Pg 449 #7 WITH MODIFICATIONS! Write a program that asks the user for a file name, and then ask the user for up to 100 input values. Write the user input values to the file. Then read the ...

Argue why wireshark should be outlawed and it is a clear

Argue why Wireshark should be outlawed and it is a clear violation of privacy act and then argue why it should not be out outlawed and that it is a vital resource to be freely used and does not violate the privacy act

Write a program that takes as input an xy center value and

Write a program that takes as input an x,y center value and radii for two circles, draws them in a turtle (Python) window, and prints whether they intersect or not. You should show intersecting circles, and show non-inte ...

Show that the set alldfa and allnfa is complete for one of

Show that the set ALLdfa and ALLnfa is COMPLETE for one of the main complexity classes ( P, NP , PSPACE etc)? Do we need to show 2 things for proving it is complete? Meaning for eg: If ALLdfa is in P and all other sets i ...

Task 1implement a queue on a char array do not use queue

Task 1 Implement a Queue on a char [] array. Do not use ::Queue:: class from the STD library for this example. The user will input a string and the program will return the string with each letter in the string duplicated ...

Question in relational algebra is the set difference

Question : In relational algebra: is the set difference commutative or not and Why? What is the difference between multivalued and composite attribute? Explain with Example.

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As