BÝLKENT UNIVERSITY

DEPARTMENT OF COMPUTER TECHNOLOGY AND PROGRAMMING

CTP203 Operating Systems

Spring 2000

Lab Midterm

Name/Surname:

Instructor : Can Uður Ayfer Assistant : Ece Yargý

Date : 20 May 2000 12:00

Please read the questions carefully. Attempt ALL the questions. Each question is 10 pts. There are 10 questions on four pages

1

What is the UNIX “who” command used for?

  1. To list the users authorized to use this computer
  2. to get more detailed information on users (like the finger command)
  3. to list the users currently logged on to the system
  4. to list a detailed information on the user who has sent you the mail you just received

2

What does the following UNIX cp command do?

cp /usr/local/bin/w*

  1. copies all the files from /usr/local/bin to the directory /usr/local/bin/w
  2. copies some of the files from /usr/local/bin to the directory /usr/local/bin/w
  3. Wouldn’t do anything because the command “copy” should be used instead of “cp”.

  1. Wouldn’t do anything because there are not sufficient number of arguments (parameters).

3

Suppose you have logged on to host “gunes” as user “cayfer” and you have the following files (listed by the “ls –l” command) in your home directory:

-rw-r--r-- 1 cayfer 16188 Feb 15 19:56 listserver.pl
drwxr-xr-x 3 cayfer 1024 Jan 30 02:53 lserver
drwxr-xr-x 4 ayfer 512 Apr 12 13:16 perl
-rw-r--r-- 1 cayfer 716800 Jan 31 12:50 perl.tar
-rw-r--r-- 1 root 18003 Jul 29 1997 platypus.gif
---------- 1 cayfer 18943 Feb 3 1998 shell_help.htm

Please indicate CLEARLY which of the following stements are TRUE and which of them are FALSE.

  • You can delete the file “shell_help.htm” because its owner is cayfer. FALSE
  • You cannot delete the file “shell_help.htm” because its file name is invalid. FALSE
  • You must use the “-h” option to delete file “shell_help.htm” because its access flags are all “-“. FALSE
  • “rm perl” command will not work. TRUE
  • “perl” listed the third line must be a program file because it is “executable”. FALSE
  •  

    4

    Suppose you have logged on to host “gunes” as user “cayfer” and you have the following files (listed by the “ls –l” command) in your home directory:

    -rw-r--r-- 1 cayfer 16188 Feb 15 19:56 listserver.pl
    drwxr-xr-x 3 cayfer 1024 Jan 30 02:53 lserver
    drwxr-xr-x 4 ayfer 512 Apr 12 13:16 perl
    -rwxr--r-- 1 cayfer 716800 Jan 31 12:50 perl.tar
    -rw-r--r-- 1 root 18003 Jul 29 1997 platypus.gif
    ---------- 1 cayfer 18943 Feb 3 1998 shell_help.htm

    Please indicate CLEARLY which of the following stements are TRUE and which of them are FALSE.

  • “listserver.pl” is a PERL script and everybody can execute it by simply typing “listserver” to the prompt. FALSE
  • “listserver.pl” is a PERL script and everybody can execute it by simply typing “listserver.pl” to the prompt. FALSE
  • “listserver.pl” is a PERL script and everybody can execute it by simply typing “perl listserver” to the prompt. FALSE
  • “listserver.pl” is a PERL script and everybody can execute it by simply typing “perl listserver.pl” to the prompt. TRUE
  • Nobody can execute this script since it is not executable for any type of users. TRUE (FALSE answers will be accepted too)
  •  

    5

    Suppose you have written a C program and entered its source to a file called “myprog.pl”. To run this program; (Please indicate CLEARLY which of the following stements are TRUE and which of them are FALSE.)

  • you must first make the file “myprog.pl” executable. FALSE
  • you must first rename the file “myprog.pl” to “myprog.exe” and then make it executable. FALSE
  • you must compile and link the program with the C compiler TRUE
  • you must compile and link the program with the PERL compiler FALSE
  • you must use the PERL interpreter instead of C compiler because the file name has an extension of “.pl”. FALSE
  • 6

  • Please indicate CLEARLY which of the following stements are TRUE and which of them are FALSE.
  • The UNIX “vi” program is a general purpose text file editor. TRUE
  • The UNIX “vi” program is a text file editor to write PERL programs. FALSE
  • The UNIX “vi” program is a general purpose program file editor to write programs. TRUE/FALSE
  • The UNIX “vi” is NOT a program; it is a command. FALSE
  • 7

    What does the the “cat *.txt | less” command do?

    1. Catalogues all files with extension “txt” to a file called “less”
    2. Converts all files with extension “txt” to programs
    3. displays a detailed file name listing (with access flags, creation date, size etc) of files with extension “txt” and places the result in a file called “less”.
    4. displays the contents of files with extension “txt” and places the result in a file called “less”.

    1. displays the contents of files with extension “txt” and passes the result to the program called “less” as its standard input.

    8

    Suppose you have logged on to host “gunes” as user “cayfer” and you have the following files (listed by the “ls –l” command) in your home directory:

    -rw-r--r-- 1 cayfer 16188 Feb 15 19:56 listserver.pl
    drwxr-xr-x 3 cayfer 1024 Jan 30 02:53 lserver
    drwxr-xr-x 4 ayfer 512 Apr 12 13:16 perl
    -rwxr--r-- 1 cayfer 716800 Jan 31 12:50 perl.tar
    -rw-r--r-- 1 root 18003 Jul 29 1997 platypus.gif
    -r-------- 1 cayfer 18943 Feb 3 1998 shell_help.htm

     

    If you want to delete everything (files and directories) under this directory; you must use the UNIX command:

    1. rm –all files
    2. rm –a files directories
    3. rm –l *
    4. rm –r *.*
    5. rm –r * (although there is a ownership problem, this is the command to use)

    9

    Suppose you have a text file (“ctp203_list_of_students.txt”) which contains a list of 3450 students registered to CTP-203 course. A few example lines out of this file looking like :

    Name        Surname   Grade
    =========== ========= =====
    Ugur Ayfer gr:A+ Ali Veli gr:B- Hasan Huseyin gr:C Ayse Fatma gr:C etc. etc.

    Which UNIX command would you use to display students who got an A+ in this course

    1. grep "A" ctp203_list_of_students
    2. grep ":A" ctp203_list_of_students
    3. find "A+" ctp203_list_of_students

    1. grep ":A+" ctp203_list_of_students

    1. sort A+ | more ctp203_list_of_students

    10

    The following PERL program is supposed to be executed by using exactly two parameters, file1 and file2, and should make sure file1 exists and file2 does not exist. If file1 exists and file2 doesn’t; then the program should copy file2 to file2. There are some errors in this program. You should find at least 8 errors to get 10 points for this question. You will get 5 points for 5-7 errors you find. No partial grade will be given for less than 5 errors you find.

    (Hints : The special variable $#ARGV contains the subscript of the last parameter and the array @ARGV contains the command line arguments.)

    # Program starts here.
    # Count the number of arguments
    if ( $#ARGV != 2 ) {
    1
    print "Incorrect number of arguments!\N":
    2
    exit;
    }

    # get the first and second arguments
    file1 = @ARGV[0];
    3, 4
    file2 = @ARGV[1];
    5, 6
    # check whether they exist

    if ( ( -d $file1) && ( -f $file2)) { 7
    print FILE1 FILE2 "Error! $file1 does not exist or $file2 exists!\n";
    8
    system;
    }

    open (INFILE, $file1);
    open (OUTFILE, $file2);
    9

    while (<INFILE>) {
    $line = <STDIN>;
    10
    print OUTFILE $_;
    }

    print "Done\n";

     

    1: Must compare against 1. $#ARGV is the subscript of the last argument and subscripts start at 0 in Perl.

    2: Must use \n. Line must end with ; not :

    3,5. scalar vars need a $. file1= … must be $file1 = …

    4,6 : References to array elements must start with $ not @ (must be $file1=$ARGV[0])

    7: There is logic error here. Not syntax error. Must use the OR (||) operator instead of AND (&&).

    8: print FILE1 FILE2 doesnot make sense. Neither FILE1 or FILE2 should be there!

    9: To open a file for output the ">" redirector must be used. Should be open (OUTFILE, ">$file2");

    10: Logic error here. Should read (and already have done it) from INFILE. Console input is absolutely nonsense here.