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

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 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