{"id":19383,"date":"2021-07-20T16:09:29","date_gmt":"2021-07-20T16:09:29","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/07\/20\/c-program-help\/"},"modified":"2021-07-20T16:09:29","modified_gmt":"2021-07-20T16:09:29","slug":"c-program-help","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/07\/20\/c-program-help\/","title":{"rendered":"C program Help"},"content":{"rendered":"<p>\u00a0In most cases the document is first sent to a print server (which may be running on your local machine). \u00a0This server is a process that waits for incoming documents needing printing, assigns incoming documents to their proper printer queue, and sends them one at a time to the proper printer. <\/p>\n<p> A print server may manage more than one printer, and may accept requests from many different computers via network connections. \u00a0Its main job is to ensure that multiple documents are not sent to a single printer at the same time. \u00a0The print server assigns an identification number to each document being printed, which allows users to check on the progress of the print job. \u00a0This identification number may also be used to cancel print requests, or change their job priority. \u00a0Some print servers maintain statistics on printer usage, and provide billing information for users who pay to print documents. <\/p>\n<p> Printers are good examples of slow I\/O devices, as it is not uncommon for a print job to take several minutes to complete. \u00a0We cannot keep programs blocked waiting for their print jobs to complete, so printing is almost always\u00a0done asynchronously (in the background).\u00a0Print servers often store copies of the document to be printed in a working directory on disk. \u00a0This technique is called &#8220;spooling&#8221;. \u00a0The advantages of using this technique are that it allows programs to request a document be printed, and then forget about it. \u00a0The print server then assumes the responsibility of watching the printers and sending the next document to a printer when it becomes ready. \u00a0Another advantage is that a user can continue to modify a document after it is queued for printing, without interfering with the printing of the original version. <\/p>\n<p> For this assignment you are going to write a print server (in C). \u00a0 <\/p>\n<p> You will not use actual printers, but will instead &#8220;print&#8221; documents by appending them to the end of a file on disk. \u00a0Since real printers (as do all devices) appear to be files, your server will not be very different from an actual print server. \u00a0Your server will support at least two simulated printers. <\/p>\n<p> Your print server will accept print requests over a network (using TCP\/IP) <\/p>\n<p> This means you will need to write client programs which talk to the server <\/p>\n<p> A client will need to discover the server&#8217;s IP address using multicasting <\/p>\n<p> In addition to the server, you will need to write two small utilities which talk to the server:The print server will sleep for 30 seconds per job, to simulate the time it takes for the printer to complete <\/p>\n<p> a print command (similar to lp) which will request a file be printed (possibly stdin) <\/p>\n<p> a status command which will <\/p>\n<p> locate (discover) the server on the network <\/p>\n<p> show the printers supported by the server <\/p>\n<p> show the contents of the queue associated with a particular printer <\/p>\n<p> allow the user to cancel a print job which has not completed <\/p>\n<p> display statistics (# bytes\/pages printed for each job) <\/p>\n<p> New print quests will store a copy of the document to be printed in a spool directory, and print this document when the printer is available. <\/p>\n<p> Your server may optionally run a document through some sort of filter before printing it. \u00a0This will be part of the request from the client. <\/p>\n<p> Multithreading <\/p>\n<p> We haven&#8217;t covered this in class yet (like much of what this project will rely upon). \u00a0I suggest reading ahead, and investigating these topics on your own with the intent of fixing things once we cover them in class. \u00a0 I think you&#8217;ll get more out of the later lectures this way, since you&#8217;ll have an idea of what you need to focus on. <\/p>\n<p> Having said that, one of the problems the server will need to address is how to handle more than one task at a time. \u00a0The server may need to simultaneously listen for new print requests, handle one or more new print requests just received, send a new document to a printer which has just finished its previous job, respond to one or more status requests. <\/p>\n<p> That sounds like a lot of stuff. \u00a0But each task is really pretty simple if we looked at it separately. <\/p>\n<p> We have already seen one technique for performing concurrent (at the same time) tasks: \u00a0forking a new process. \u00a0For this assignment we&#8217;ll use a better technique: \u00a0POSIX threads. \u00a0Most of the problems we are faced with will be relatively easy to solve using these threads. \u00a0Consider that the tasks listed above will need to communicate with each other, and that multiple concurrent tasks will need to access a print queue. \u00a0How do we keep these from interfering with each other? \u00a0POSIX threads provides mechanisms to share memory among different tasks (threads) and to prevent more than one thread from accessing the same area of memory at a time. \u00a0 I have allocated two class sessions to discuss POSIX threads. <\/p>\n<p> Networking <\/p>\n<p> This is an important part of the assignment, and we have a large block of class time to cover this topic. \u00a0You will communicate with your server over a network using sockets and TCP\/IP. \u00a0These sockets act like files, so in a sense it will be like writing to a file and having another process read the data out. \u00a0Most of your work will be to set up the network<br \/> connection, and to know when new data is available. <\/p>\n<p> You&#8217;ll also use multicasting to allow the client programs to locate their server. \u00a0In a sense you will send a query &#8220;is my print server out there&#8221; out to the network, and if a machine running your server sees the request it will respond. \u00a0Once the client receives the response it will have enough information to establish a normal TCP\/IP session. \u00a0(This will be an important feature since it is likely that more than one of you will be working on the same CSE machine at the same time). <\/p>\n<p> Questions <\/p>\n<p> As the name suggests, a queue is an important data structure for this project. \u00a0What will be stored in the queue? \u00a0Some sort of structure which contains information on a print request. \u00a0For example the document name, the user making the request, the identification number, the filename in the spool directory. <\/p>\n<p> Q: \u00a0Why is the filename included, couldn&#8217;t we just use the document name?<br \/> A: \u00a0 What if a user printed two different documents with the same name? \u00a0Or two different versions of the same file? <\/p>\n<p> Q: \u00a0Where do the identification numbers come from?<br \/> A: \u00a0 The server creates them. \u00a0They just need to be unique numbers. \u00a0A counter would work fine. <\/p>\n<p> Q: \u00a0How do I know how many pages are in a document?<br \/> A: \u00a0 We approximate this based on the number of lines. \u00a0Assume 60 lines per page. \u00a0One line per linefeed in the document.<\/p>\n<p> Q: \u00a0How wide is a page?<br \/> A: \u00a0 It doesn&#8217;t matter for our purposes. \u00a0We can assume that the printer truncates lines that are too wide (as some older printers did) <\/p>\n<p> Q: \u00a0How do the client programs talk to the server?<br \/> A: \u00a0 They send a multicast request for their server, and use the response to learn the contact information (address and port) <\/p>\n<p> Q: \u00a0How does the server know which printers to use?<br \/> A: \u00a0 Have it read a configuration file when it starts. \u00a0Each printer should have a one-word unique name. <\/p>\n<p> Q: \u00a0How many queue data structures will I need?<br \/> A: \u00a0One per printer. <\/p>\n<p> Q: \u00a0What is a filter script?<br \/> A: \u00a0A shell script that acts as a filter. \u00a0The script is started with the document as its stdin. \u00a0The script writes a modified document on its stdout. \u00a0The server prints this. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0In most cases the document is first sent to a print server (which may be running on your local machine). \u00a0This server is a process that waits for incoming documents needing printing, assigns incoming documents to their proper printer queue, and sends them one at a time to the proper printer. A print server may [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20],"class_list":["post-19383","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-programming"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/19383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=19383"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/19383\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=19383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=19383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=19383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}