Write a short shell script called c-interp

Assignment Help Computer Engineering
Reference no: EM131497404

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] [<list-of-files>]

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

Reference no: EM131497404

Questions Cloud

Do banks require projected financial statements : Purpose: The purpose of this exercise is to explore the practical importance and use of projected financial statements in the banking business.
Create an object class for something of interest to you : Create an object class for something of interest to you. Use a constructor to populate class object and provide methods to retrieve each of the class attribute.
What is the projects payback period : alculate the IRR, the NPV, and the MIRR for each project, and indicate the correct accept-reject decision for each.
What are the management issues explain briefly : Accenture is a strong firm globally. What are the three major threats you see that Accenture may face in a country of your choice?
Write a short shell script called c-interp : CS 146 Assignment. 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
Briefly describe current european and us industry standard : Critically analyze current European and United States industry standards or recommendations for any Information Technology (IT) area or subarea.
Illustrate a matrix organizational chart : Which approach to conflict resolution would you use to resolve a disagreement between top-level managers, regarding a firm's strategic plan?
Compare and contrast restructuring and reengineering : List ten "dos and don'ts" regarding development of organizational charts.
Evaluate the capacity of most common distribution channels : Evaluate the capacity of the most common distribution channels available for the new product launch to provide consumers with easier access to the product.

Reviews

len1497404

5/16/2017 3:26:00 AM

Style and modularity of questions 2 and 3 are important. Try to keep the design simple and elegant. You will probably have to make extensive use of the course texbook and the online manual. Write a filter in C that prints M lines out of every N. It can be done using the shell and awk, It's more simple and efficient in C. The program's name is "every".

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd