{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Final_Example3 - i x".u't ml.3 ‘ 3 “fl?“ p ‘7...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i x" ...u't ml .3 ‘ 3 - “fl?“ _ _ p ‘7 CS 2413 Final -‘ v . "1".» ~.____J_$ _v .- ‘- .. ... ., v '.-’_"-_ '7‘ - ‘" —. "" l. :15 Suppose a pet! program. grab. is invoked with the command: grab -a file: file2 file3 and supp-Jae £3.12: sauna: the :19; ‘d;:‘.‘ .;-1 "in? with: 151.123 2 c.3433: xix?) 3.3-1 "-iré“ and file? contains ‘dirS . “dirfi' and 4'“ '7", .--- At. the Star: of the program: {at What is the list value of MRGV‘.‘ ib.‘ What is the value of SMRGV? [cl What value is used in the asignment for OARGV: Sval I GARGV; Id: If the following statements are executed first. -4 $a = shift; ll} Sb - pop; 3d =- o; i. What is the value of 33.? ii. What is the value of 3b? iii. What is the value of SABGV? (e) On the other hand if the following statement were to be executed first. 33. " shift; Sb 2 shift; 0d 3 (>; i. What is the value of 3b? ii. What is the value of 0d? ‘2. [20] Write a Perl script. called replines. which will replace flQCkmel ultras; in the second file with the corresponding lines from the first file. Thus to replace lines 15 throflughtggfw in outfile with the corresponding lines Erom infile the command would be: mlines 15 25 infile outfile Notice that all the other lines of outfile are still in the file. You may assume that outfile has the same number of lines as infile. ; .{20} Write a Perl script pyrap, which Wlll search all TEXT fileswhigh 1:9" finder any of the directories Whose names are given 'on the command line for the regulaffipréfiion which is git-en as the 5:51. argument on the command line. A sample invocation:- pgrep ’cat.tdog’ filel £1132 £11233 "30‘- .Xn ISP {Internet Service Pro-rider? is concerned about. a user named maynrd spamming —.u;ii so they “'13! a. too; to lock in the Li»:— 1 ran-”Lsgx'syslcg an»; pm; on: IRE-353‘- —.:it a about :15-213d's email usage on March 7 Write a perl script which will determine the that] size of 'he outgoing email written by may-nan} as well as the total number of email messages received by mayfiard on March T. The syslog file will include several months worth of data. for many users. The lines (simplified from the real syslog data) look like: .-_. ., f" 7 ,, A—___r rrrrrr —— a _ . t _ (c. 7 _ , Mar 5 21:58:18 medusa sendmailf6432]: to=<ma ardOmedusa)‘, Statz'Sent Ha: 7 00:06:37 medusa sendmaill7248]: from=<maynard0medusa>. size=681 The output should look like: maynard 1573889 bytes mailed out 798 emails received [25] Write a C function with prototype: {anl‘fi‘l-rwcaftl .-..+ a1 . “Cad. Infill) int delrec(unsigned int pun, chair- fulfillmugiifigped int 1:32); A filecan beconsid- ered to he a SQUEBQEPFTGCQEQBf alfixed size, say is?) where the first rs; bytes are to be considered record 0, the next rsz bytes are rgcnord 1, .. .. The functionfiglrecjwill delete the rsz bytes in record gum in the file. file. moving'every record from that point on forward one record. The function must both Open and close the file. If successful, delrec will return a 0 else delrec will return -1. The function should use low- level I /O. U! b'. [25] Implement a. low—level popen‘ called ppopen. The prototype is: int. ppopenCcoust char *comand, const char *ty‘pe); . o W . The function ppopen will fork and exec command after havrng created one pipe. If type == "r‘ then the pipe will be set for comand to write back to the parent process via. stdout while if type :2 ‘w" then the pipe will be set for the parent process to write over the pipe to conmand‘s stdin. The function ppopen will return the appropriate file descriptor so that the parent can communicate, in the appropriate direction, with command. 'bn'..'h" " .7. M wwwmmmul marmmrt nuc- ._ mu —- -.....__—'1';.... {25] You have a program called snort which anifi's the network and writeupgfilfi (van/laglalert, all of the suspicious packets. Unfortunately there are'many ofthe'se'a'rid you jifif‘want 'fo ' Watch some particular types of packets as they arrive. 1«trite a C program. called gsnort. that will look at all new entries in the file lvar/log/alert and will print those which match your regular expression as they arrive to stdout. This could be done on the command line . - r.: r 3.15:: a ;=.pr':- -:; .urm tail —r‘ Mar; logr'aLerr. l egrep regexp 7: £35: regexp is the regular EprE’SEEOE‘. of interest. A sample invocation wont-l gsnort [25] Write a C program which will create a total of 37 processes all of which Will have their awn separate pipe. i.e. all processes will be able to write to all other processes but each process will only read from its own pipe. in addition each process will have an assigned index. 0 .. . :36. Each process will check it's pid and if its pid is even. it will write its pid to each of the processes with even indices while if its pid is odd it will write its pid to each of the processes with odd indices {but no process writes to itself). Then each process will read all the manages written to its pipe and print on stdout. for each message. a line similar to: Process 35894 heard from process 35992 Be careful that your code doesn‘t hang! [25] 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 “Imp/dispatch“. You should assume that this fifo already exists. The dispatcher program reads a message from the fifo. execs the appmpriate server and then writes the data to the server. The server is expecting its data via stdin and will write its data to stdout. The dispatcher must be certain that the server's stdout is redirected to the fifo. created by the client. named in the message. The format of the message is: Data Field (first byte - last byte) program name 0-255 -—__.__._.—- return fifo name 256—511 data 512- 1023 Write the dispatcher program for this system assuming that there may be several dispatcher programs running simultaneously. In addition the program should be written so that zombies are not created. Note that the dispatcher does not terminate but constantly reads messages from the dispatch pipe. ...
View Full Document

{[ snackBarMessage ]}