Instruction manuals

Linux 56 Assignment

Description
Linux Assignment for MCA
Published
of 32
92
Published
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Share
Transcript
  http://www.cs.cmu.edu/~213/oldexams/ MCQhttp://www.cs.toronto.edu/~reid/csc209/tests/    1) Write a Linux shell script (/bin/bash) which has two command line parameters, a username and a filename. The script should determine the number of times the user with that username is logged into thesystem and write that number to the gien file. !f the file already exists, the script should output an error message. ome commands you might li#e to use are $grep%, $wc% and $who%. olution&'/bin/shif  *' +e -   then username0*1 filename0*- if  +f *filename   then echo *filename already exists2 else set 3who 4 grep 56*username 5 4 wc3 echo *1 7*filename fielse echo 8sage& *9 :username7 :filename72fi-);ie an example of a Linux file management system call and describe what it does. Solution: Example: read(fd, buffer, nbytes)It reads a certain number of data bytes from a file to a buffer and returns the number of bytes read or an error code <)Write a = program which uses Linux system calls to create a new process. The child process shouldcreate an empty file called $abc% and then terminate. The parent process should wait for the child processto terminate and then output the process number of the child process. >on?t forget to chec# for error conditions.'include :stdio.h7'include :sys/types.h7main()@   pidAt child int status B!LC Dfp child0for#() if (child00+1) printf(5Crror creating child process5) else if (child009) @ fp 0 fopen(5abc5, 5w5) if (fp00E8LL) printf(5Crror creating file5) else fclose(fp) F else @ child0wait(Gstatus) if (child00+1) printf(5Crror waiting for child process5) else printf(5HldIn5, (long)child)F } J)Write an explanatory note on enironment ariables. Klso write a = program that outputs the contents of its enironment list.Kns& The enironment list is an array of character pointers, with each pointer containing the address of a null+terminated = string. The address of the array of pointers is contained in the global ariable environ & extern char DDenironWe?ll call environ     the environment pointer , the array of pointers the enironment list, and thestrings they point to the environment strings .y conention, the enironment consists of   name = value  strings,=/=MM program that outputs the contents of its enironment list.'include 55!nt main(int argc, char Darg)@ int i char DDptr extern char DDeniron for (ptr 0 eniron Dptr 0 9 ptrMM) /D and all en strings D/ printf(5HsIn5, Dptr) exit(9)FN)When a process creates a new process using the for#() operation, which of the following state is sharedbetween the parent process and the child processOP) tac#Q)ReapS) hared memory segmentsKnswer& nly the shared memory segments are shared between the parent process and the newly for#edchild process. =opies of the stac# and the heap are made for the newly created process.U)Row does the distinction between #ernel mode and user mode function as a rudimentary form of protection (security) systemOKnswer& The distinction between #ernel mode and user mode proides a rudimentary form of protection inthe following manner. =ertain instructions could be executed only when the =V8 is in #ernel mode. imilarly,hardware deices could be accessed only when the program is executing in #ernel mode. =ontrol oer wheninterrupts could be enabled or disabled is also possible only when the =V8 is in #ernel mode. =onseuently,the =V8 has ery limited capability when executing in user mode, thereby enforcing protection of criticalresources.19)Which of the following instructions should be priilegedO11) et alue of timer.1-)ead the cloc#.1<)=lear memory.1J)!ssue a trap instruction.  1N)Turn off interrupts.1P)Xodify entries in deice+status table.1Q) witch from user to #ernel mode.1S)Kccess !/ deice.Knswer& The following operations need to be priileged& et alue of timer, clear memory, turn off interrupts,modify entries in deice+status table, access !/ deice. The rest can be performed in user mode.1U)What is the purpose of system callsOKnswer& ystem calls allow user+leel processes to reuest serices of the operating system.-9)What are the fie maYor actiities of an operating system in regard to process managementOKnswer&a. The creation and deletion of both user and system processesb. The suspension and resumption of processesc. The proision of mechanisms for process synchroniZationd. The proision of mechanisms for process communicatione. The proision of mechanisms for deadloc# handling-1)What are the three maYor actiities of an operating system in regard to memory managementOKnswer&a. [eep trac# of which parts of memory are currently being used and by whom.b. >ecide which processes are to be loaded into memory when memory space becomes aailable.c. Kllocate and de+allocate memory space as needed--)What are the three maYor actiities of an operating system in regard to secondary+storage managementOKnswer&\ Bree+space management.\ torage allocation.\ >is# scheduling-<)What is the purpose of the command interpreterO Why is it usually separate from the #ernelOKnswer& !t reads commands from the user or from a file of commands and executes them, usually by turningthem into one or more system calls. !t is usually not part of the #ernel since the command interpreter issubYect to changes.
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x