{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Final_Example1 - CS 2—113 Final 17:161 Salppitase ii Perl...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 2—113 Final 17 :161. Salppitase ii. Perl progr'un fern; is invoked with the command: fern -czv -f filel f11e2 f11e3 ‘IJ mil suppose filel containslthe lines “diri” while f11€2 contains "dirQ‘X "511:3" .mui "dull" and f11e3 contains "d1r5" 1nd "dire"; A: the start of the program: 2.1: What is the list value of @ARGV‘.‘ __,_.-/ ib) “has is the value of WARM? :' ".‘.'h.ir, value :5 lrr'lLf'ElPll M 8751 a, 5731 = MEG'J; ) “l .Il‘i After the following statements have been executed. $9. = $11.57.; , 3:: = pop: \u'w'lt : = Shift; 31.31. '4 7 .2 $d = O; _"'.'::i‘-‘:":.a 1’“ ‘*‘-‘- 1’ tun- tum“ fir-L; (fixtg‘d‘ 1*. ‘f‘ 'l‘ '<' ) _ WM-U-L '1" “*9 WELL: :5 'he \‘Tllllr f Sb.‘ 5 What is rlie value of 33." u.._—..- Jun/‘5: ids» L 4— :1; Whir i~ rile value '-l' SARGV" “lieu-.2. ‘5" 5‘ What is the value of MHG‘J'.1 rel h". following the above instrurtions. the following instriirtions are exeCuted: Sb = 0- deval- ! Sc = 0; :lqub @d = 0; .LmJ-l i. What is the value of ad? {LL-1L j-l- 2. [‘20] Write a Perl script” called split. which will break a given file into files with a fixed number of lines. Both the name of the file and the number of lines per file {with the exception of the last file} will be given on the command line. The output files will have the same name 'b‘ the original file but with a numbered extension added to the end {.33. .1. .23. 3. Thus an invocation whivh will split the file file . txt into chunks of 100 lines creating the files file.t:t.0, file.txt.1, split file.txt 100 . would be l {20] A system administrator wants to automatically search the text files under a number of directories for various regular expressions. Thus he has set up several files ‘nut contain the names of directories under which he washes ‘0 search. Write a Perl script. pgrep which will rem-i these fir’f-S. whose names we given on the command line. 1nd Will search all TEXT files which are under am: of the directories in those files for the regular expression. gin-n up: the first argument ull the cumnmnd iine. A sampie invocation isystem and users '11"? files containing directoriesn pgrep ’ r001: ’ /etc/security/system fete/security/users l. {20] Intruders into a computer system typically install a. root kit which replaces a number of binaries With trojaned binaries and cleans up all of the various log files. You want to know when this happens and which tiles were changed so you have created a file. f11es.md5. which contains .1 list. of the :ill files followed by some white space and an RID-‘3 Slctamurw ml the' :iie. F‘hrir-xlacwiiy you Will run 3. program thit creates .1 file. filesneumdi. which contains :1 list of the all current files and their MD?) signatures. Write a peri script which will compare both files and report the names of tiles that are: 0 ln files.md5 and not in f11es.new.:nd5 - [:1 151195 .neumds and no: in files.md5 - Files whose RID-5 signature has changed. {in-iris? .:-i_ztput assume (lira-razrj.‘ names have no white space-,4 /etc/hosts.deny deleted _ Ivar/tmp/ . ssh/passwords added /etc/shadow MD5 signature changed A sample entry in either of the files looks like: letc/shadow 3km . SksKNfleMquMP . KDM2w8/3u023 {25] Write a C function with prototype: OI int delrecordsmnsigned int mum, unsigned int num, char *file. unsigned int rsz): A file can be considered to be 3. sequence of record of a fixed size. say rsz where the first rsz bytes are to be considered record 0. the next rsz bytes are record 1. The function delrecords will delete the num records starting with record number mum in the file. file. moving all undeleted records after mum up nun records. The function must both open and close the file. If successful. delrecords- will return a 0 else delrecords will return -1. The function should use low-level I/O. [5425] Write a C function with prototype: int insblk(char #111121, unsigned @annlm unsigned @3213: unsignedtizflmj char *jileoue, unsigned int :52); A file can be considered to be a sequence of record of a fixed size, say rsz, where the first rsz bytes. are to be considered record 0, the next rsz bytes are record 1 from {E into a. new file called lfileoutl time but you may assume that they are less thanS4096 in size} The function must also both open and close the files. If successful insblk will return a 0 else insblk will return -1. The function should use low-level I/O. V6 [25] Implement a low—level popen, called ppopen. The prototype is: int ppopen(const char *command, const char *type); The function ppopen will fo__rk and exec c0,_a.nd after having created one pipe. If tvpe is “r ” then the W1 e set or command bac parent v1a. st out it hile if type :5 . ‘n then the pipe will be set for the parent recess to write over I ' 3:? to :crmand's ‘ din. The function ppopen will return the appropriate file descriptor of the pipe so that the parent can communicate, in the appropriate direction, with command. 1/ [25] Write a function, called compose, that will be passed two structures of the form: struct command { char *cmd; _/* name of comand */ :fiilel, char *arnglG]; [=11 Null terminated argv list of arguments to command (including command) */ }; The function composeO with FREQFYPE: MP int composeCstruct command Cindi, struct command cmd2); will fork and exec both commands, piping the output of the first command into the second command. The function returns 0 on success and -1 on error. n, “8. 9 [25] Write a C program which will create a total of 33 processes all of which will have t eir own separate i e i.e. 3W all other processes but m’a- - - -ss W1 on v read fra_- 1 5 ram one. Each -___'_‘I_—__.——fl-_-'_-n process will be assigned a unique M Each process will write it’s in ex and id (you define the message structure) to everv other— (but not to itself). Thengach process will read all the messages if". itten t9 its pipe and print on stdout, for each message, a line similar to: l [ii-11$ 894 m-ex = ear- om nrocess 5992 index 17 Be careful that your code doesn‘t hang! [30] In the system that you are writing, many programs (called clients) will be executing and will need other programs, called servers, to process some data. In this version of the system each program will write to a well known fifo (named pipe) with the name “/tmp/dispatch”. Each dispatcher program repeatedly reads a message from the fife, execs the requested server (program) after connecting the pipes. The seme W. The dispatc er must be certain that the server’s stdout is redirected to the return fifo named in the message and that the server’s stdin is redirected to the data fifo named in the message. It is the clients responsibility to write the data to the data fifo. The format of the message is: Data Field (first byte - last byte) program name (null terminated) 0-127 return fifo name (null terminated) 128-255 data fifo name (null terminated) 256-383 Write the dispatcher program (in C) for this system assuming that there may be saveral dispatcher programs executing at the same time. There should be no long-lived zombies created nor should the dispatcher wait for a potentially long time. The dispatcher should follow the current path (bad idea) to find the program when exec’ing. Note that a. dispatcher does not terminate but constantly reads messages from the dispatch fifo. ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern