Document Details

EndearingFairy1361

Uploaded by EndearingFairy1361

Czech University of Life Sciences Prague

Tags

unix commands practical tasks operating systems

Summary

This document is a set of practice questions and tasks focused on Unix commands. It includes multiple-choice questions and practical tasks. Ideal for students preparing for exams related to operating systems.

Full Transcript

(?) – I`m not sure about the answer 1) The legal entity (general) partnership is characterized by: A) Limited liability B) Specialized professional management separated from owners C) Sharing risk among owners 2) Which factor(s) of the PEST analysis can be identified as political factor(s) : A)...

(?) – I`m not sure about the answer 1) The legal entity (general) partnership is characterized by: A) Limited liability B) Specialized professional management separated from owners C) Sharing risk among owners 2) Which factor(s) of the PEST analysis can be identified as political factor(s) : A) Inflation rate B) Population growth rate C) Trade restrictions and tariffs 3) Economies of Scope means: a) Reduction in the average costs of production when output is increased b) Benefits arising from carrying on related activities c) Benefits arising from diversification 4) External financial resources include: a) Sale of share b) Bank borrowings c) Accrued liabilities – This is for internal 5) Which from following items is/are reported as fixed costs? a) Insurance b) Energy for operating machines c) Interests margin 6) The difference between budgeted sales revenue and the break-even point is called: a) Target net profit b) Margin of safety (?) c) Contribution margin 7) A profit and loss account (income statement) gives information about firm’s : a) Assets b) Earnings before interests and taxes c) Opportunity costs 8) Cash flow from operating activities includes: a) Payment of dividends of shareholders b) Purchase of production machines c) Cash inflow from sales of goods 9) Among the most influential factors on pricing belong(s): a) Inflation b) Prices of competitors c) Target profit 10) Which of the following situations may decrease price sensitivity: a) Easy to make comparison b) Availability of product substitutes c) Real or perceived necessities 11) The experience-curve: a) Portrays the relationship between pricing and experience – cumulating (?) b) Portrays the price of working experience c) Portrays the experience – based efficiency, unit cost will decline when accumulated volume increases 12) Market skimming is: a) A strategy setting prices to skim profit from the market. Examples include: innovate digital b) Suitable for products have a long-life cycle c) Generally, be prohibited by the law 13) The legal entity role trade/role proprietor is characterized by: a) Limited liability b) Relatively great freedom from regulations c) Simple decision – making 14) Which factor(s) of the PEST analysis can be identified as economic factor(s): a) Inflation rate b) Research and development c) Trade restriction and tariffs 15) Economies of scale means: a) Reduction in the average costs of production when output is increased b) Benefits arising from carrying on related activities c) Benefits arising from diversification 16) Internal financial resources include: a) Retained earnings b) Sale of share c) Accrued liabilities 17) Which from the following items is/are reported as variable costs: a) Raw materials b) Insurance c) Energy for operating machines 18) The level of sales at which revenue equals expenses is called: a) Target net profit b) Margin of safety (?) c) Break-even point 19) A balance sheet gives information about firm’s: a) Variable costs b) Earnings before interest and taxes (?) c) Equity and its structure 20) The assets reported in a balance sheet includes following item(s): a) Accounts payable b) Accounts receivable c) Inventories 21) Among the most influential factors on pricing belong(s): a) Cost b) Lack of product substitutes c) Product differentiation 22) Which of the following situations may increase price sensitivity? a) Have higher total expenditure b) Lack of product substitutes - (Decrease) c) Product differentiation 23) Which of the following objectives of pricing strategy would be considered inappropriate: a) achieving cooperative relationship with competitors to share the market (?) b) enhancing product or brand image c) expanding market share or achieving financial performance 24) Penetration pricing is: a) To secure high profit margin through high prices b) Typical in mass market products, like chocolate bars, food stuffs, household goods (?) c) Not appropriate for products with a long product life cycle (PLC) or to launching (?) Not sure which answer is correct 25) Which of the following ratios would be used to measure a company’s liquidity? a) Debt to equity ratio b) Current ratio (?) c) Cash ratio (?) Not sure which answer is correct 26) Among the most influential factors on pricing belong(s): a) Cost b) Loan interests c) Target profit 27) Which factor(s) of the PEST analysis is/are identified as technological factor(s) a) Inflation rate b) Research and development c) (?) 28) A merger: a) Is a purchase of one company by another one with no new company being formed b) Is a voluntary fusion on (…) equal terms c) Is a combination of two or more companies to form a new legal entity (company) 29) Equity financing includes: a) Retained earnings b) Sale of share c) Bank borrowings 30) Overheads (overheads costs) are also reported as: a) Fixed costs b) Indirect costs c) Opportunity costs 31) The difference between sales and variable costs is called: a) Margin of safety b) Operating leverage c) Contribution margin 32) A balance sheet gives information about firm’s a) Assets b) Liabilities ( Maybe 2 answers ? ) c) Fixed costs 33) Which of the following situations may decrease price sensitivity: a) Lack of product substitutes b) Real or perceived necessities c) Easy to make price comparison 34) Which of the following statements is (are) false? a) Setting priority among objectives of pricing strategy is subject to management’s judgment b) The extent of pricing flexibility is independent of top management’s goals c) Objectives of pricing strategy should be revisited in the end of pricing situation analysis Don’t know the answer 35) Price discrimination is: a) Charging a different price for the same/service in different markets b) Requires different price elasticity of demand in each market. Examples like prices for rail (…) same journey at different times of the days c) An unfair pricing, generally be prohibited by the law 36) Internal financial resources include: a) Retained earnings b) Sale of share c) Accrued liabilities 37) Which of the following objectives of pricing strategy would be considered inappropriate or unreasonable a) Achieving cooperative relationship with competitors to share the market b) Enhancing product or brand image c) Expanding market share or achieving financial performance Theoretical Questions: Question 1: Question 2: Question 3: Question 4 is missed Question 5: Question 6: Question 7: Unix Practical Tasks: 1 task: Task 2: Task 3: Task 4: Task 5: Task 6: Task 7: Home page / Courses / EIE69E / 04_Tests & Quizzes / Credit_test Starting the test Monday, January 13, 2025, 4:35 PM State Completed Test completion Monday, January 13, 2025, 4:42 PM Trial length 7 minutes 4 seconds Stamp 6.00 out of a possible 10.00 ( 60 %) Comment Unfortunately you have to take the credit test again Task 1 Correctly Points 1.00 / 1.00 To move to a subdirectory data located in current directory you will use the following command: Select one of the options offered: and. cd data  b. go to data C. change date d. data E. mv./data The correct answer is: cd data. Task 2 Incorrectly Points 0.00 / 1.00 Suppose you list a directory and get the following output of ls -l. Which of the following commands will delete the folder old_logs? -rw-r--r-- 1 user user 378 Dec 23 10:54 2020-12-22_logs -rw-r--r-- 1 user user 378 Dec 23 10:53 2020-12-23_logs drwxr-xr- x 1 user user 4096 Dec 23 10:52 old_logs Select one of the options offered: and. delete -d old_logs b. rm old_logs C. We cannot remove a directory that is not empty d. rmdir old_logs  E. rm -r old_logs Your answer is incorrect. The correct answer is: rm -r old_logs. Task 3 Correctly Points 1.00 / 1.00 Redirect both standard and error output of program prog1 into a file log : Select one of the options offered: and. prog1 2>1 > log b. prog1 >2> log C. prog1 > log >> log d. prog1 2> | log E. prog1 2>&1 > log  The correct answer is: prog1 2>&1 > log. Task 4 Incorrectly Points 0.00 / 1.00 Find all lines beginning with a number in file data.txt : Select one of the options offered: and. find -P "[0-9]*" file.txt b. find -P "^\d" file.txt  C. grep -P "[0-9]*" file.txt d. ls ^[0-9]* file.txt E. grep -P "^\d" file.txt The correct answer is: grep -P "^\d" file.txt. Task 5 Correctly Points 1.00 / 1.00 Choose the only correct way how to use ls with the option for long (detailed) output : Select one of the options offered: and. ls-l b. Ls-l C. ls -l  d. ls-s E. ls -L The correct answer is: ls -l. Task 6 Correctly Points 1.00 / 1.00 What character is used as an escape character so the following character's special meaning is ignored: Select one of the options offered: and. @ b. S ame character as we want to use (eg ** will ignore *) C. ^ d. \ E. / The correct answer is: \. Task 7 Correctly Points 1.00 / 1.00 Create a directory programs in your current working directory: Select one of the options offered: and. mkdir programs  b. newdir programs C. md programs d. make dir programs E. touch./programs The correct answer is: mkdir programs. Task 8 Incorrectly Points 0.00 / 1.00 What will be the result of running script.sh displayed below by running a command./script.sh xyz script1.sh: #!/bin/bash if [ $# -gt 1 ] then Many else echo Few fi Select one of the options offered: and. Both words will be printed out to the terminal b. A word "Few" will be printed out to the terminal C. A string "xyz" will be printed out to the terminal d.  A word "Many" will be printed out to the terminal E. Script will throw an error The correct answer is: A word “Few” will be printed out to terminal. Task 9 Incorrectly Points 0.00 / 1.00 What are values ​of $1 and $2 in script.sh after running./script.sh *.txt in a directory displayed below: -rwxr-xr-x 1 user user 76 Jul 22 17:23 script1.sh -rw-rw-r-- 1 user user 16 Jul 22 17:37 data1.txt -rw-rw-r-- 1 user user 9 Jul 22 17:38 data2.txt -rw-rw-r-- 1 user user 25 Jul 23 10:12 data.csv Select one of the options offered: and. $1 = data1.txt data2.txt $2 = b. $1 = *.txt $2 = C. $1 = data1.txt $2 = data2.txt d. $1 = *.txt  $2 = data1.txt data2.txt E. $1 = script.sh $2 = "data1.txt data2.txt" The correct answer is: $1 = data1.txt $2 = data2.txt. Task 10 Correctly Points 1.00 / 1.00 What permission type(s) is necessary in order to run a program: Select one of the options offered: and. read b. read AND execute C. execute  d. write E. s-bit The correct answer is: execute. ← Examples to practice Go to... Testing Center → UNIX Complete Study Guide Basic Concepts 1. What is an operating system kernel? – A program that resides in main memory and controls hardware – Starts programs and controls their execution according to user requirements 2. What components make up an OS distribution? – Kernel of OS – System programs – Libraries – Configuration files 3. What are the file types in Unix and their symbols? – Regular files (-) – Directory (d) – Link file (l) – Control file for character data transfer (c) – Control file for blocked data transfer (b) File System & Permissions 4. What is an i-node and what information does it store? – Type of file – Access rights – UID and GID – Date of last write, use, and modification – Size of file in bytes – Total number of used blocks – Total number of hard links – Addresses of data blocks 5. What is the difference between hard and soft links? Hard Link: – Is a directory item (couple of filename and i-node number) – Cannot cross file systems – Cannot link to directories – Deleting original file doesn’t affect hard link Soft Link: – Special file containing path to target – Can cross file systems – Has its own i-node – Can link to directories – Becomes invalid if target is deleted 6. How are file permissions organized? Access rights are defined for: – Individual owner – Group owner – Other users Rights include: – Read (r) – Write (w) – Execute (x) 7. What are special permission bits? – s-bit (Set User ID/Set Group ID) – t-bit (Sticky bit) Effects: When s-bit is set on executable: Changes effective owner of process When t-bit is set on directory: For binary programs: Prevents the OS from freeing all program pages after termination., For directories: Allows users to create files but only delete their own files. 8. What does the command chmod 755 file do? A: Sets the permissions of the file to rwxr-xr-x. Processes 8. How are processes created in Unix? – New processes are crested using through fork() system call – Exception is the process swapper (or init), created by OS kernel at system start 9. What happens during fork() system call? 1. OS creates new process (child) that is copy of calling process (parent) 2. Child process gets its own page table 3. Child process gets its own u-area 4. Return values differ: In parent process: PID of child process In child process: 0 10. What are the basic process states? – Running in user mode – Running in kernel mode – Ready to run – Blocked 11. What is multitasking in Unix? Unix uses pre-emptive multitasking: – Process can run continuously only for limited time (time quantum) – After time quantum expires, kernel stops running process – Scheduler chooses next process according to priority – Process stopping due to time quantum expiration is called pre-emption 12. What are process groups? - A process group is a collection of processes identified by a group ID (PGRP). The leader of the group has a PID equal to PGRP. Shell Commands 12. What is the basic shell command format? name [-options] [arguments] 13. What are escape characters in shell and their purpose? - ” ” - Special meaning of all characters inside except $ is canceled - ’ ’ - Special meaning of all characters inside including $ is canceled - - Special meaning of the character that follows is canceled 14. What happens during the execve() system call? - The OS finds the executable file, checks permissions, and verifies the magic number. - Changes the effective user ID if the setuid bit is set. - Copies program arguments and environment to the new process stack. - Initializes the process memory and sets the instruction register to the program's entry point. 15. What is a pipe in shell? – Shell creates temporary file (buffer) in filesystem – Ensures controlled data transfer from standard output of prog1 to standard input of prog2 – Syntax: prog1 | prog2 16. What are file descriptors? – Small nonnegative integers (starting from 0) used for file identification – Standard descriptors: 0: standard input (keyboard) 1: standard output (display) 2: error output (display) 17. What are escape characters in the shell? - \ Cancels the special meaning of the character that follows. - " Cancels special meaning for all characters except $. - ' Cancels special meaning for all characters, including $. Signals 16. What are signals in Unix and their purpose? – Signals inform processes about asynchronous events – Processes can send signals using kill() system call – OS kernel can also send signals to processes 17. What are the three most important signals? – SIGINT (2): Sent by keyboard handler after CTRL+C – SIGKILL (9): Signal for process termination, cannot be ignored – SIGTERM (15): Signal for standard process termination Shell Variables 18. What are the types of shell variables? Local variables: – Contain information for running shell – Can be used in scripts – Not accessible in processes started from shell – Usually named with small letters Environmental variables: – Accessible in processes started from shell – Some have standard meaning (HOME, USER, etc.) – Usually named with capital letters Common Commands 19. Important command examples: – Create file: touch filename – Create directory: mkdir dirname – Change directory: cd path – List files: ls [options] – Remove files: rm [options] files – Copy files: cp source destination – Move files: mv source destination – View file contents: cat filename – View process status: ps [options] – Kill process: kill [signal] PID – Search text: grep pattern file 20. How to run a program in background? – Add & at end of command:./program & – Switch running program to background: Ctrl+Z, then bg – Bring background program to foreground: fg Regular Expressions and Text Processing 21. Basic regular expression patterns: – ^ - Start of line – $ - End of line –. - Any single character – * - Zero or more occurrences – [] - Any character in brackets – [^] - Any character not in brackets – [0-9] - Any digit – [a-z] - Any lowercase letter Commands and Utilities 22. What commands are used for common tasks? Print a string: echo "text" Display manual pages: man command Create a file: touch filename List files: ls View file contents: cat filename Report running processes: ps 23. What is the command to find all processes of a user? ps -u username Advanced Topics 24. What is an environmental variable? How is it different from a local variable? Environmental Variable: Accessible to child processes; defined using export NAME=value. Local Variable: Limited to the shell or script where it is defined; set using NAME=value. 25. How does the file cache improve performance? The file cache stores recently accessed blocks of data to reduce disk I/O operations, speeding up read/write processes. 26. How do you run a program in the background? Use & after the command, e.g.,./program &. Answers I got wrong from 3 UNIX Credit tests. File, directory, and variable Write command to pull a file Write cmd to pull a directory Which of following commands will list all files in current directory that include characters m or c? ls *[mc]* Becuase ls list the content in files, * Matches any sequence of characters & [mc] Matches either 'm' or 'c' Obtatin a sample of first five student accounts defined in the system using pipeline cat /etc/passwd | grep student | head -n 5 cat /etc/passwd - gives the output of contents of /etc/password, grep filters the output to only students, head -n 5 - limits the output to the first five lines and | combines together multiple commands. Switch a running process from background to foreground: fg - to run program from bg to fg (terminate process un fg: Ctrl + C) bg - to run program from fg to bg (terminate process un fg: Ctrl + Z) Switch from a direcory /home/user1 into /etc using one of following options cd../../etc cd change directory../../ moves up two directory levels etc target directory Redirect both standard and error output of program prog1 into a file log: prog1 2>&1 > log prog1 is the cmd being executed. 2>&1 merges file descriptor 2 into the same file descripter 2 > execueted into file log Let’s suppose student accounts are created using pattern xstudent00..xstudent99,Provide with all student accounts: grep xstudent /etc/passwd grep is used for searching text patterns within file. What is the next step after finishing a shell script script1.sh in a text editor? Set permissions to execute. What command is used to search/find a file: find What loop is best used for iteration throughout files? for What special variable stores return value from the last executed command? $? $# - no of arguments Delete all files from folder Trash in your current directory. ls -l drwxrwxrwx 1 user user 1212575289 Oct 16 17:48 Trash rm Trash/* rm – remove, Trash/* is ony trash directory and not sub directory. Program prg,is located in current directory. How do we run such program?./prg./ for current directory and without it, it will the shell looks for the executable in directories listed in the PATH environment variable A command ls -a will print out: also hidden files (begin with „.“) UNIX COMPLETE STUDY GUIDE 1. What is an operating system kernel? Answer: A program that is in the main memory and controls hardware means of the computer, starts programs and controls their execution according to user requirements 2. What components make up an OS distribution? Answer: Kernel of OS System programs Libraries Configuration files 3. What are the file types in Unix and their symbols? Answer: Regular files (-) Directory (d) Link file (l) Control file for character data transfer (c) Control file for blocked data transfer (b) 4. What are descriptors and what are they used for? Answer: A descriptor is a small nonnegative integer (starting from 0) that process can use for file identification. After successful file open, the system calls open() or creat() return this descriptor that process can use in the following read and write calls. 5. What are the standard descriptors and their uses? Answer: 0 - standard input (keyboard) 1 - standard output (display) 2 - error output (display) 6. What is the basic shell command format? Answer: name [-options] [arguments] 7. How are processes created in Unix? Answer: New process arises only if some running process calls the system service fork(). The exception is the process swapper (or init if the system has no swapper), which is created by OS kernel after start of the system. 8. What happens during fork() system call? Answer: 1. OS creates a new process (child process) that is a copy of the calling process (parent process) 2. The child process has its own page table 3. The child process has its own u-area 4. Return values differ: a. In parent process: PID of child process b. In child process: 0 9. What are the basic process states? Answer: Running in user mode Running in kernel mode Ready to run Blocked 10. What is multitasking in Unix? Answer: In Unix multitasking is pre-emptive, meaning: Process can run continuously only for limited time (time quantum) After time quantum expires, kernel stops the running process Scheduler chooses next process according to priority The stopping of process due to time quantum expiration is called pre-emption 11. What are signals in Unix and their purpose? Answer: Signals inform processes about asynchronous events. Process can send signal to another process using system service kill(). The OS kernel can send signals to processes as well. 12. What are the three most important signals? Answer: SIGINT (2) - Keyboard handler sends to process running on foreground after CTRL+C SIGKILL (9) - Signal for process termination, cannot be ignored or treated SIGTERM (15) - Signal for standard process termination 13. What information is stored in an i-node? Answer: Type of the file Access rights UID and GID Date of last write, use, and modification Size of file in bytes Total number of used blocks Total number of hard links Addresses of data blocks 14. What is the difference between hard and soft links? Answer: Hard Link: Is a directory item (couple of filename and i-node number) Cannot cross file systems Cannot link to directories Soft Link: Special file containing path to target Can cross file systems Has its own i-node Can link to directories Becomes invalid if target is deleted 15. How does shell execute commands? Answer: Shell: 1. Interprets special characters in the strings 2. If string is an alias, replaces according to alias table 3. If string is user defined function, executes this function 4. If string is inner shell command, executes it 5. Otherwise considers string to be path to executable file 16. What are escape characters in shell and their purpose? Answer: " " - Special meaning of all characters inside except $ is canceled ' ' - Special meaning of all characters inside including $ is canceled \ - Special meaning of the character that immediately follows \ is canceled 17. What is pipe in shell? Answer: Shell creates temporary file (buffer) in file system and ensures controlled transfer of data from standard output of prog1 to standard input of prog2 when using syntax: prog1|prog2 18. What information is stored in process table? Answer: PID - Process number Process state Field of signals Pointer to page table Pointer to u-area 19. What information is stored in u-area? Answer: Real and effective user and group name Current directory and root directory Table of descriptors I/O parameters Signal treatment Control terminal Result and parameters of system call 20. What are process groups? Answer: Each process is member of process group. Process groups are denoted by natural number PGRP. Each group has leader - process whose PID equals PGRP. 21. What happens during system call execve()? Answer: 1. OS finds file determined by path, checks magic number and execution right x 2. If file has user s-bit set, changes effective owner of process 3. Stores running parameters and environmental parameters on system stack 4. Creates new process page table 5. Copies parameters into new process stack 6. Inserts starting address of new binary program into processor instruction register 22. What are file permissions organized? Answer: Access rights are defined for: Individual owner Group owner Other users Rights include: Read (r) Write (w) Execute (x) 23. What does file cache contain and how is it used? Answer: File cache consists of buffers. Each buffer has: Header with status and pointers Data block It's used for caching read and written data blocks of files. 24. What happens during file open operation? Answer: 1. OS searches for file's i-node following complete path 2. Checks file's access rights 3. Copies i-node to i-node cache if not present 4. Assigns first free row in descriptor table 5. Sets up file table entry 6. Returns file descriptor to process 25. What are the types of shell variables and their differences? Answer: Local variables: Contain information for running shell Can be used in scripts Not accessible in processes started from shell Usually named with small letters Environmental variables: Accessible in processes started from shell Some have standard meaning (HOME, USER, etc.) Usually named with capital letters 26. What is a function in shell and how is it defined? Answer: Function is defined as: name_of_function() { commands } Can be deleted using: unset name_of_function 27. What is condition testing in shell? Answer: Can be done through: Inner test [ condition ] Outer test (program test) Result stored in variable ? 0 if condition satisfied 1 if condition not satisfied 28. What is the purpose of t-bit (sticky bit)? Answer: If set on: Binary program: After program termination, OS won't free all program pages in memory Directory: Users can create new files but can only delete their own files What is I-node? An I-node is a data structure that stores metadata about directory files. These are the addresses of data blocks, the number of hardlinks. It contains metadata (information) about the file type, access rights, individual and group owner, time of last write, use, modification, file size, etc. Signals in Unix? a) They inform processes about asynchronous events b) 2 SIGINT sends the keyboard driver to the process that is running in the foreground after pressing CTRL + C 9 SIGKILL signal to end the process, cannot be treated 15 SIGTERM signal to end the process c) Signal handling is a code solution that ignores the sent process signal, except for signal 9, which cannot be treated d) Kill -9 1000 Soft Link Softlink - a symbolic link or link, is implemented as a file containing a path. It can be created with the ln command. The soft link is a separate file and has its own i-node. Advantage - they can also reference files and directories in other file systems. Disadvantage - if we delete the file to which the soft link refers, the system will not detect it and there may be a number of soft links in the system that do not link to anything. Hard link hard link is equivalent to a file stored in the hard drive – and it actually references or points to a spot on a hard drive. A hard link is a mirror copy of the original file. The distinguishing characteristic of a hard link from a soft link is that deleting the original file doesn't affect a hard link, while it renders a soft link inoperable. Rm command a) Write rm command that deletes all files in the ~/prog directory which names begin with a number character and end with the.gz extension a) rm ~/prog/[0-9]*.gz b) Write rm command that deletes all files in the current directory whose names begin with the character * b) rm./\** a) Write a command that prints from the file ~/data all lines that contain a string starting with the character x or y and ending with character dot A) cat ~/data | grep -P "^[xy].*\.$" b) Write a command that prints from the file ~/data all lines that start with the string prag B) cat ~/data | grep -P "^prag*" c) Write a command that prints from the file ~/data all lines that contain the string *file* C) cat ~/data | grep -P "\*file\*" a)Write the chmod command so that the access rights to the file ~/a are set as follows: Rwxr-xr-x And the user s-bit and group s-bit are set as well b) write the chmod command so that the access rights to the file ~/b are set as follows: r-xr—r—and the t-bit is set as well: A) chmod 6755 ~/a B) chmod 1544 ~/a Expansion expressions in the shell a) Explain what expansion expression are used for: Expansion expression is used for categorization of file names or paths It has form of complete or incomplete path in which occurs b) Describe the rules for creating expansion expressions: 1) Shell substitutes expansion expression with all those paths that comply with it (we say that shell expands the expansion expression) 2) After expansion shell asks kernel to execute the command c) Write the ls command with an expansion expression to print information from the /bin directory about all files that begin with the letters p or s: ls -l /bin/P* - information about all files in /bin the name of which begins with p are printed ls -l /bin/s* - information about all files in /bin the name of which begins with s are printed d)) Write the cp command to copy all files with a two-character name from the current directory to the ~/adr directory cp.//??~/adr a) Grep “ris” ~/a Paris b) Grep ar ~/a Prague Paris Hamburg mars c) Grep ‘^m’ ~/a Moon mars 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 02_Seminar 1_summary Započetí testu Úterý, 6. prosince 2022, 21.47 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.57 Délka pokusu 10 min. 5 sekund Známka 13,87 z možných 15,00 (92,47%) Úloha 1 An operating system (OS) is system software that manages computer hardware, software resources, and Správně provides common services for computer programs. Bodů 1,00 / 1,00 Vyberte jednu z nabízených možností: Pravda ! Nepravda Správná odpověď je 'Pravda' Úloha 2 Unix operating system cannot have graphic user interface, it's just a terminal Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda Nepravda ! Správná odpověď je 'Nepravda' Úloha 3 Most of the servers run unix based operating system Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda ! Nepravda Správná odpověď je 'Pravda' https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 1 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 4 Choose areas where unix based operating systems play a dominant role Částečně správně a. Desktop computers and laptops Bodů 0,89 / 1,00 b. Mobile phones c. Servers! d. IoT! e. Embedded systems! f. Visual effects demanding high performance g. Cloud computing! h. Supercomputers! i. Submarines, Space industry and aviation industry (planes)! j. Control systems! k. Security experts! Vaše odpověď je částečně správná. Vybrali jste správně 8. Správné odpovědi jsou: Servers, IoT, Embedded systems, Visual effects demanding high performance, Cloud computing, Supercomputers, Submarines, Space industry and aviation industry (planes), Control systems, Security experts Úloha 5 Unix based operating systems are NOT usually open source Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda Nepravda ! Správná odpověď je 'Nepravda' https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 2 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 6 Tag existing strictly Unix variants: Správně Bodů 1,00 / a. Solaris by Sun Microsystems! 1,00 b. BSD by University of California! c. Xenix by Microsoft! d. HP-UX by Hewlett Packard! e. AIX by IBM! f. Fedora by Red Hat g. Android by Google h. MacOS by Apple Vaše odpověď je správná. Správné odpovědi jsou: Solaris by Sun Microsystems, BSD by University of California, Xenix by Microsoft, HP-UX by Hewlett Packard, AIX by IBM Úloha 7 What programming language was used to develop unix operating system Správně Bodů 1,00 / a. C++ 1,00 b. C! c. R d. Python e. Pascal f. Shell script g. Fortran h. Java Vaše odpověď je správná. Správná odpověď je: C. https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 3 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 8 To what device can we install unix operating system? Správně Bodů 1,00 / a. All of mentioned! 1,00 b. Server c. Desktop computer d. Smartphone e. Embedded device f. Virtual machine Vaše odpověď je správná. Správná odpověď je: All of mentioned. Úloha 9 Assign correctly years and the operating systems Částečně správně Unix OS 1969 ! Bodů 0,71 / 1,00 Linux OS 1981 " Mac OS 2001 ! MS-DOS 1991 " MS Windows 1985 ! Android 2007 ! Symbian 1998 ! Vaše odpověď je částečně správná. Vybrali jste správně 5. Správná odpověď je: Unix OS → 1969, Linux OS → 1991, Mac OS → 2001, MS-DOS → 1981, MS Windows → 1985, Android → 2007, Symbian → 1998. https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 4 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 10 Tag stricltly linux distributions Částečně správně a. Debian! Bodů 0,60 / 1,00 b. Mint c. Ubuntu! d. Fedora e. Red Hat! f. Solaris g. iOS h. CentOS i. PC-DOS j. OpenSUSE! k. ArchLinux! l. Slackware m. Gentoo! n. Xbox OS Vaše odpověď je částečně správná. Vybrali jste správně 6. Správné odpovědi jsou: Debian, Mint, Ubuntu, Fedora, Red Hat, CentOS, OpenSUSE, ArchLinux, Slackware, Gentoo https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 5 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 11 What are the advantages of Unix operating systems? Částečně správně a. Compatibility with a third party software Bodů 0,67 / 1,00 b. Gaming industry c. Security and privacy! d. Open source (free of charge, custom configurations)! e. Package & update management! f. Performance g. Stability & Sustainability! h. Large community support Vaše odpověď je částečně správná. Vybrali jste správně 4. Správné odpovědi jsou: Security and privacy, Open source (free of charge, custom configurations), Package & update management, Performance, Stability & Sustainability, Large community support Úloha 12 What is the command to print a string into standard output (terminal)? Správně Bodů 1,00 / Odpověď: echo ! 1,00 Správná odpověď je: echo Úloha 13 What is the command to see other command's manual page? Správně Bodů 1,00 / Odpověď: man ! 1,00 Správná odpověď je: man https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 6 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 14 What is the command to create a file? Správně Bodů 1,00 / Odpověď: touch ! 1,00 Správná odpověď je: touch Úloha 15 What is the command to print content of the file Správně Bodů 1,00 / a. print 1,00 b. echo c. cat ! d. console.log() e. printf() Vaše odpověď je správná. Správná odpověď je: cat. 03_Seminar 3_summary + ◀ 01_Introduction fun test Přejít na... processes ▶︎ https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 7 of 7 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 03_Seminar 2_summary Započetí testu Úterý, 6. prosince 2022, 21.31 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.44 Délka pokusu 13 min. 21 sekund Známka 8,80 z možných 9,00 (97,78%) Úloha 1 Choose a command executing an interactive system-monitor process-viewer and process-manager Správně Bodů 1,00 / a. ps -ef 1,00 b. top! c. none of those d. cat /etc/passwd e. ps -aux Vaše odpověď je správná. Správná odpověď je: top. Úloha 2 What is pipeline for? Správně | Bodů 1,00 / 1,00 a. alternation (if the first one ends with an error, the second one is started) b. parallelization (both programs are running simultaneously) c. cooperation (the output of the first program is connected to the input of the second)! d. serialization (the second program is started after the end of the first one) Vaše odpověď je správná. Správná odpověď je: cooperation (the output of the first program is connected to the input of the second). https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 1 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 3 Choose correct statements about C programming in Unix operating systems Správně Bodů 1,00 / a. To run a program, we first have to compile it! 1,00 b. The intstruction to print a string to the standard output is a command echo c. We first have to include line #!/bin/bash d. A compiled program is lacking of execute permission so we have to assign it. Then we run./ e. To work correctly with command line we need to include a library ! f. cc -o a_file b_file.c will create a_file with compiled code! g. The intstruction to print a string to the standard output is a command print h. The file format of programs is.cpp i. The file format of programs is.sh j. A compiled program has already execute permission. We just run./! k. To run a program, we can use syntax./.c l. By returning integer zero we indicate a successful run of the program! m. instructions in C programming does not have to be terminated by ";" n. instruction return 1 is equal to return true o. A default output of cc command is an executable file a.out! p. Main function must have at least one argument q. The file format of programs is.c! r. The intstruction to print a string to the standard output is a command printf! s. cc program.c will compile the file with the same filename t. To use most of C instructions we don't have to include library Vaše odpověď je správná. Správné odpovědi jsou: The file format of programs is.c, To work correctly with command line we need to include a library , The intstruction to print a string to the standard output is a command printf, By returning integer zero we indicate a successful run of the program, To run a program, we first have to compile it, cc -o a_file b_file.c will create a_file with compiled code, A default output of cc command is an executable file a.out, A compiled program has already execute permission. We just run./ https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 2 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 4 Assign correctly commands with their functions Správně Bodů 1,00 / Rename a file mv ! 1,00 Move file to a different folder with different name mv / ! Move file to a different folder mv ! Remove empty directory rmdir ! Remove non-empty directory rm -r ! Remove a file rm ! Vaše odpověď je správná. Správná odpověď je: Rename a file → mv, Move file to a different folder with different name → mv /, Move file to a different folder → mv, Remove empty directory → rmdir, Remove non-empty directory → rm -r, Remove a file → rm. Úloha 5 Following command Správně ls /bin/*[0-9].w? Bodů 1,00 / 1,00 will list all files in /bin directory that: a. begins with any number of any character, includes number 0 or 9 and have format of two character, first one is w b. None of these c. begins with any number of any character, includes any number on last position before file ! format of two character, first one is w d. begins with asterisk, include any number and have format starting with w Vaše odpověď je správná. Správná odpověď je: begins with any number of any character, includes any number on last position before file format of two character, first one is w. https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 3 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 6 A command grep will: Správně Bodů 1,00 / a. Select first "n" lines from the input 1,00 b. Select a column of any order c. Select all lines that includes a pattern given as argument! d. Select all occurance of a pattern given in as argument Vaše odpověď je správná. Správná odpověď je: Select all lines that includes a pattern given as argument. Úloha 7 Assign permissions to the commands correctly. Správně Qeustionmark represents that we don't know the permission. Bodů 1,00 / 1,00 chmod u=rwx rwx-???-??? ! chmod o+w ???-???-?w? ! chmod 644 rw-r--r-- ! chmod 700 rwx------ ! chmod o+w chmod: missing operand after `o-x' ! chmod 341 -wxr----x ! Vaše odpověď je správná. Správná odpověď je: chmod u=rwx → rwx-???-???, chmod o+w → ???-???-?w?, chmod 644 → rw-r--r--, chmod 700 → rwx------, chmod o+w → chmod: missing operand after `o-x', chmod 341 → -wxr----x. https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 4 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 8 Check correct statement about bash scripting: Částečně správně a. first line is #!/bin/bash! Bodů 0,80 / 1,00 b. While creating a script, the owner is given a permission to execute the file c. We can write down any instructions from any known programming language d. script file format is.sh e. Scripts in unix don't allow programming syntaxes such as IF statements or loops f. We can only run programs (commands) that are known in system variable PATH! g. To run a script, we first have to compile it h. script file format is.bash i. To run a script we can use a syntax./.sh! j. While creating a script, we have to assign ourselves a permission to execute the file! k. first line is to import libraries fro standard input and output Vaše odpověď je částečně správná. Vybrali jste správně 4. Správné odpovědi jsou: script file format is.sh , first line is #!/bin/bash, We can only run programs (commands) that are known in system variable PATH, While creating a script, we have to assign ourselves a permission to execute the file, To run a script we can use a syntax./.sh Úloha 9 What of following characters is pipeline? Správně Bodů 1,00 / a. _ 1,00 b. \ c. |! d. > e. / Vaše odpověď je správná. Správná odpověď je: |. ◀ 03_Seminar 3_summary + Přejít na... Example of exam test ▶︎ processes https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 5 of 5 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 03_Seminar 3_summary + processes Započetí testu Úterý, 6. prosince 2022, 21.15 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.28 Délka pokusu 13 min. 11 sekund Body 16,00/17,00 Známka 18,82 z možných 20,00 (94,12%) Úloha 1 Assign commands with its functions Správně Bodů 1,00 / Not such command mkfile ! 1,00 Create a file touch ! Change directory cd ! Create a directory mkdir ! Správná odpověď je: Not such command → mkfile, Create a file → touch, Change directory → cd, Create a directory → mkdir. Úloha 2 What is the command to report a snapshot of the current running processes? Správně Bodů 1,00 / Odpověď: ps ! 1,00 Správná odpověď je: ps https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 1 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 3 Assign correctly Správně Bodů 1,00 / interactive process viewer top or htop ! 1,00 report a snapshot of the current processes. ps ! terminate running processes kill ! Správná odpověď je: interactive process viewer → top or htop, report a snapshot of the current processes. → ps, terminate running processes → kill. Úloha 4 "awk" command is for pattern scanning and processing language. Správně Write a command that will print the fifth column of the following text Bodů 1,00 / 1,00 a. awk {'print $5'}! b. awk {print $5} c. awk -d " " -f5 d. awk '{print $5}' e. awk $5 Správná odpověď je: awk {'print $5'}. Úloha 5 Type a command that will only filter lines that don't include number Správně Bodů 1,00 / Odpověď: grep [^0-9] ! 1,00 Správná odpověď je: grep [^0-9] https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 2 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 6 Assign commands correctly Správně Bodů 1,00 / head output the first part of files ! 1,00 grep print lines matching a pattern ! cut remove sections from each line of files ! tail output the last part of files ! sed stream editor for filtering and transforming text ! Správná odpověď je: head → output the first part of files, grep → print lines matching a pattern, cut → remove sections from each line of files, tail → output the last part of files, sed → stream editor for filtering and transforming text. Úloha 7 Using output of command ls as an argument of a command rm would be: Správně Bodů 1,00 / a. rm -ls 1,00 b. ls rm c. rm ls d. ls `rm` e. ls -rm f. rm `ls`! g. ls | rm h. rm rm | ls Správná odpověď je: rm `ls`. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 3 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 8 What is the correct syntax of the for loop in bash? Správně Bodů 1,00 / 1,00 a. for (variable=; variable < ; variable ++) { ; } b. for in ! do done Správná odpověď je: for in do done. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 4 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 9 Assign correctly IF statements Správně Bodů 1,00 / if [ -f 'foo$3' ]; then 1,00 echo "Unix" print "Unix" if 'foo$3' is a regular file ! fi if [ $foo -ge 3 ]; then echo "Unix" print "Unix" if variable foo is greater or equal to 3 ! fi if [ "$test" == "ge 3" ]; then echo "Unix" fi print "Unix" if the content of test variable is a string "ge 3" ! Správná odpověď je: if [ -f 'foo$3' ]; then echo "Unix" fi → print "Unix" if 'foo$3' is a regular file, if [ $foo -ge 3 ]; then echo "Unix" fi → print "Unix" if variable foo is greater or equal to 3, if [ "$test" == "ge 3" ]; then echo "Unix" fi → print "Unix" if the content of test variable is a string "ge 3". Úloha 10 Type a command that will find out how many instances of program sshd are running on the system Správně 1) list all processes using only one neccessarry modifier (standard syntax, not BSD) Bodů 1,00 / 1,00 2) filter lines with string sshd 3) google how to count lines in unix 4) link it to one command that you write down here Odpověď: ps -e | grep sshd | wc -l ! Správná odpověď je: ps -e | grep sshd | wc -l https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 5 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 11 Type ps -f Správně PPID is a parent process ID. Bodů 1,00 / 1,00 From the output we can tell following: a. processes bash and ps -f have the same PID b. processes bash and ps -f have no relationship when it comes to creating processes c. bash is a parent of ps -f process! d. process ps -f is a parent of the running bash Správná odpověď je: bash is a parent of ps -f process. Úloha 12 Write down a command that will list processses owned by a user root. Správně Use minimum of modifiers Bodů 1,00 / 1,00 Odpověď: ps -u root ! Správná odpověď je: ps -u root https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 6 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 13 1) Create c program infi.c Správně Paste following code: Bodů 1,00 / 1,00 #include #include int main () { while(1) {printf("Christmas is coming\n");} return 0; } 2) Compile and run the program For compiling and running program you have to use following: a. cc infi.c./infi.c b. chmod 766 infi.c./infi.c c. chmod 700 infi.c cc infi.c./infi.c cc d. cc infi.c!./a.out Správná odpověď je: cc infi.c./a.out. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 7 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 14 1) Create c program infi.c Správně Paste following code: Bodů 1,00 / 1,00 #include #include int main () { while(1) {printf("Christmas is coming\n");} return 0; } You have just run the program. Terminate the program and choose what worked: a. CTRL + D b. CTRL + C ! c. kill a.out d. kill "Chritmas is coming" e. CTRL + ALT +DEL Správná odpověď je: CTRL + C. Úloha 15 Remove the string printf("Christmas is coming\n"); Správně Run the endless loop program in the background Bodů 1,00 / 1,00 (google how to run process in background in unix) type the command of running in background correctly assuming the name of compiled program is a.out Odpověď:./a.out & ! Správná odpověď je:./a.out & https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 8 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 16 Terminate the endless loop in background. Správně In order to do that we will: Bodů 1,00 / 1,00 a. find process name using ps aux | grep a.out kill b. Press CTRL + C c. Processes running in background cannot be terminated d. find PID using ps aux | grep a.out! kill Správná odpověď je: find PID using ps aux | grep a.out kill. Úloha 17 Remove string printf("Christmas is coming\n"). Nezodpovězeno Run the program again in the background. Počet bodů z 1,00 Type a command to bring the process in front Odpověď: " Správná odpověď je: fg 1 ◀ 02_Seminar 1_summary Přejít na... 03_Seminar 2_summary ▶︎ https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 9 of 9 Otázky z UNIXU 1. Signály v Unixu a) K čemu se signály využívají Informují procesy o asynchronních událostech b) Jako příklad uveďte několik signálů 2 SIGINT posílá ovladač klávesnice procesu, který běží na popředí po zmáčknutí CTRL+C 9 SIGKILL signál pro ukončení procesu, nelze ošetřit 15 SIGTERM signál pro ukončení procesu c) Ošetření signálu je řešení v kódu, které zařídí ignorování zasleného signálu procesu, výjimkou je jenom signál 9, který nelze ošetřit d) kill -9 1000 2. Deskriptory souboru a) Napište, co jsou deskriptory souboru a kde jsou uloženy malé kladné číslo (včetně 0), které systém přiděluje proudu při otevření. Descriptory mohou označovat Soubory, Roury, Schránky Jsou uloženy v tabulce descriptorů. b) Napište, k čemu se deskriptory používají Slouží k identifikaci otevřených proudů v dalším voláním služeb systému. c) Jaké deskriptory jsou přiřazeny standartnímu vstupu, standartnímu vstupu a chybovému vstupu. 0 standartní vstup 1 standartní výstup 2 chybový výstup 3. Návratová hodnota volání služby fork() a) Jakou hodnotu vrací služba fork() v dětském procesu 0 b) Jakou hodnotu vrací služba fork() v rodičovském procesu PID dětského procesu 4. Přeložíte a spustíte program Main( ) { fork ( ); if ( fork ( ) ==0 ) pause(); fork ( ); fork ( ); pause(); } Kolik procesu zůstane zablokovaných procesů a kolik procesů ve stavu running nebo ready to run? 10 jich bude zablokovaných (asi ready to run) 5. Napište příkaz, který z adresáře ~/data odstraní všechny soubory začínajícím malým písmenem nebo číslicí 7. rm ~/data/[[:lower:]7]* (expanzivní výraz) 6. Napište složený příkaz, který z adresáře /etc vypíše pouze informace o podadresářích začínajícím písmenem X, (Informace o podadresářích které začínají jiným písmenem než X a informace o ostatních souborech příkaz vypisovat nebude) ls -l /etc | awk '$1 ~ /^d/ && $9 ~ /^X/' ls -l /etc/X* | grep '^d' 7. Přístupová práva k regulárnímu souboru ~/výpis a jste nastavili následujícím příkazem chmod 666 ~ /vypis jak bude vypadat devět znaků, které vypíše příkaz ls -l ~ /vypis ? rw-rw-rw- (110110110) 8. Přístupová práva a s-bity k regulárnímu souboru ~/vypis jste nastavili následujícím příkazem chmod 6755 ~/vypis Jak bude vypadat prvních deset znaků, které vypíše příkaz ls –l ~/vypis -rwsr-sr-x 9. Napište příkaz: a) Který vypíše hodnotu proměnné HOME echo $HOME b) Vypíše hodnotu proměnné „?“ echo $? 10. Napište: a) příkaz ls tak, aby z adresáře /bin vypsal informace o souborech, jejichž jména začínají písmenem a, c nebo r ls /bin | grep ^s nebo ls -l /bin/[acr]* b) příkaz ls tak, aby z adresáře /etc vypsal informace o souborech, jejichž jména končí číslicí c) příkaz ls tak, aby z adresářů /etc a /bin vypsal informace o souborech, jejichž jména jsou tříznaková. ls -ld /bin/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9] nebo ls -ld /bin/??? 11. a) Napište rozdíl mezi programem a procesem program je zdrojový kód a může mít více procesů proces je běžící program b) Nakreslete strukturu souboru, který obsahuje binární program c) Nakreslete strukturu procesu 10. Jak vypada vyrovnavaci pamet pro prenos dat z disku a jaky je jeji ucel a) Jake je uplatneni vyrovnavaci pameti pri cteni z disku b) Jake je uplatneni vyrovnavaci pameti pri zapisu na disk Proces Cache Systém souborů Ad b)Nečeká se na odezvu disku, protože část dat jen nacachovaná Ad a)Nemusí se čekat na zpomalení zapsání dat, data se mohou zapsat se zpožděním. 11. a) Co v shellu znamena spusteni prikazu na popredi, uvedte priklad Pokud běží příkaz na popředí, tak systém čeká na dokončení příkazu, dokud neskončí, nemůžeme zadávat další příkazy b) Jak zrusime prikaz na popredi Crtr+C, vysláním signálu c) Co v shellu znamena spusteni prikazu na pozadi, uvedte priklad Běžící příkaz na pozadí nijak nekomunikuje s uživatelem a lze v průběhu běžícího příkazu zadávat další příkazy. d) Jak zrusime prikaz na pozadi Zaslání signálu (kill) e) Jak zrušit příkaz na pozadí s PID=100 kill -9 100 12. procesy A,B,C,D – viz tab PID PPID A 120 118 B 124 120 C 125 124 D 126 124 a) Nakreslete graf b) Když zrušíme A, jaké bude PPID procesu B, C, D PPID b – 118 CD budou stejné c) Když zrušíme B, jaké bude PPID procesu A, C, D A bude stejné PPID C, D – 120 d) Když zrušíme C, jaké bude PPID procesu A, B, D A, B, D budou stejné 13. a) Napište chmod příkaz tak, aby pro soubor ~/a nastavil práva takhle: rw-r--r- - Pro s-bit individuální - chmod 4644 ~/a Pro s-bit skupinový - chmod 2644 ~/a Pro t-bit - chmod 1644 ~/a b) Napište chmod příkaz tak, aby pro soubor ~/b nastavil práva takhle: rwxr-xr-x a zároveň nastavil i s-bit Pro s-bit individuální - chmod 4755 ~/a Pro s-bit skupinový - chmod 2755 ~/a Pro t-bit - chmod 1755 ~/a 6) V řádkovém souboru je: What can I do for you Xyz To be or not to be Které řádky budou výsledky regulárních výrazů: a) [n][n]*.[t][t]* 3.řádek b) [ab][d-g] 3.řádek c) [xyz]ou 1.řádek 6b) příkaz na grep s omezenim 'be..' ; napsat co se vypíše (be.. znamená, že musí obsahovat be a další dva libovolné znaky, tzn i mezeru. Proto se vypíše druhý řádek, myslím, že v zadání to bylo „to be or not to be“. Ve 3. Řádku byl text, který končil písmeny „be“ ale ten se nevypíše, protože za „be“ nejsou další dva znaky..) 14. Podrobně popsat adresářovou strukturu Unixu Soubory jsou organizovány pomocí adresářů do stromové struktury Princip organizace adresářové struktury Adresářovou položku tvoří dvojice (název souboru, odkaz na i-uzel) Odkazem na i-uzel je číslo uzlu. Hlavní adresář má číslo i-uzlu 2. (přednáška č.7 Systsoub.pdf) 15. Lokální proměnná a proměnná prostředí; vysvětlit a napsat příkazy pro jejich vytvoření lokální proměnná Do lokálních proměnných si shell ukládá svoje vlastní informace. Uživatel muže použít tyto proměnné v skriptu. Lokální proměnné nejsou přístupné v procesech, které byly z schellu Nastavení: x = string Zrušení: unset x Výpis hodnoty proměnné: echo $x Výpis všech lokálních pro.: set Proměnná prostředí jsou přístupné i v procesech, které jsou z shellu spuštěny. Některé z nich mají dohodnutý význam a procesy tak mohou zjistit například cestu k domácímu adresáři, username uživatele atd. Označují se velkými písmeny. Nastavení: export X = string Zrušení: unset X Výpis hodnoty proměnné: echo $X Výpis všech proměnných pro.: env 16. Preempce; vysvětlit co to je, jak to funguje a jestli je unix preempční proces má časový úsek a potom se vrátí systému Přerušení běhu procesu z důvodu vypršení časového kvanta se nazývá preempce. V Unixu si zapamatujme multitasking jako preemptivní. Tedy takový, že o přidělování a odebírání procesoru jednotlivým úlohám plně rozhoduje operační systém. Ten pravidelným přerušováním běžícího programu vyhodnocuje aktuální situaci. Interval tohoto průzkumu je tzv. časové kvantum (stovky ms). Podle tohoto průzkumu se systém rozhoduje, zda spustit jinou úlohu, nebo pokračovat nebo něco jiného. Toto přerušení běhu procesu důvodu vypršení časového kvanta se nazývá preempce. Výběr procesu provádí systém podle priority. 17. Kolik zablokovaných procesů v systému zůstane, pokud přeložím a spustím následující program: main() { fork(){ print{hellow}; fork(); fork(); pause(); } 2x se vypíše hellow, 8 procesů je pozastavených 18. napsat příkaz co vymaže soubory z kořenového adresáře začínající na a, h nebo z a končící na číslo rm [ahz]*[0-9] 19. chmod – nastav práva pro soubor ~/a tak aby měl rwx r-x r-x chmod 755 ~/a nastavte práva tak aby byl nastaven s-bit individuálního uživatele, skupinového uživatele, a t-bit nebyl nastaven. tzn řešení chmod 6755 ~/a 20. vymazat soubor, který začíná na „a“ nebo „h“ nebo „j“ a končí na číslici. rm [ahj]*[0–9] 21. Vlastnická práva. a) Vypsat jaká jsou. r – číst ze souboru w – psát do souboru x – spustit soubor nastavují se pro: individuálního vlastníka, skupinového vlastníka ostatní uživatele b) K čemu je x u adresáře. Pomocí x můžeme vstoupit do adresáře (prohledávat adresář) c) K čemu je w u adresáře. Pomocí w můžeme vytvářet, rušit nebo přejmenovat soubory v adresáři 22. Co je to I-uzel I-uzel je datová struktura uchovávající metadata o souborech a adresářích. Jsou to adresy datových bloků, počet hardlinků Obsahuje metadata (informace) o typu souboru, přístupových právech, individuálním a skupinovém vlastníku, času posledního zápisu, použití, modifikace, velikosti souboru aj. Systém je uchovává v superblocích??? 23. Více procesů najednou. Přerušení, čím vyvolám přerušení, atd. – Jak rovnou spustit program v pozadí V unixu je multitasking preemptivní. Preemptivní znamená, že o přidělování procesoru jednotlivým úlohám plně rozhoduje operační systém. Ten pravidelným přerušováním běžícího programu vyhodnocuje aktuální situaci. Podle zjišťovaní se systém rozhodne zda spustit novou úlohu zda pokračovat. Každý proces má vyhrazen k běhu určitý čas. Přerušení - Crtr+c, vysláním signálu, systém může přerušit Rovnou spustit program - program & Příklad: cat /etc/passwd & 24. Grep. grep čte řádku po řádce, a pokud v řádce najde instanci regulárního výrazu, vypíše řádku na standardní výstup příklad grep ^s /etc/passwd grep.*:.*:.*:1000: /etc/passwd 25. Vypiš vše, co začíná na číslo. ls | grep '^[0-9]' 26. Kopírování CP Syntaxe: cp soubor1 soubor2 cp soubory adresář Příklad: cp programy/mycat pokus cp -R adresar/podadresar novy/adresar 27. Nakreslit strom stavů procesů a popsat ho. 28. Vysvětlit co to je roura a napsat příklad. -slouží k vytvoření dočasného souboru v systému souborů a předává data mezi procesy -je to nástroj pro propojení procesů prog1| prog2, výstup prog1 jde na vstup prog2 - příklad :ls –l /etc | grep´^d´ | wc –l 29. Co si představíte pod pojmem soubor, jaké služby nad ním poskytuje OS, mody otevření Soubor v informatice označuje pojmenovanou sadu informací uloženou na nějakém datovém médiu, se kterou lze pracovat nástroji operačního systému jako s jedním celkem. Operace se soubory, vymazání, kopírování, vytváření, úprava Módy otevření – otevřít, nebo otevřít jen pro čtení 30. v historii bylo zadáno na příkazovou řádku: $hostname beta set jmeno novak - jaký bude výstup těchto příkazu: echo "jmeno: $jmeno" - vypíše: jmeno: echo 'jmeno: $jmeno' - vypíše: jmeno: $jmeno echo !ho - vypíše: hostname echo '!ho' - vypíše: !ho 31. Napište příkaz, který nastaví u souboru x přístupová práva tak, aby majitel a skupina mohli zapisovat, spouštět také majitel a skupina a číst mohli všichni. chmod 774 ~/x 32. Napiš příkaz, kterým zkopírujete soubor /etc/passwd do domácího adresáře pod stejným názvem. cp /etc/passwd ~/passwd 33. Napiš příkaz, jak vypsat obsah adresáře. (nejsem si jist, zda to tam takhle přesně bylo) ls 34. Jsou uvedeny řádky (ilustračně): mesto je krasne doma je dobre pivo piju casto Napište, které řádky ze souboru x zapíše do souboru y následující příkaz: grep '.m[ae].*' x>y Správná odpověď je "doma je dobre", protože tečka značí nějaký znak před tím "m" a v 1. řádku sice písmeno "m" je, ale je na začátku řádku, takže to nejde. 35. Napište příkaz, kterým smažete z adresáře /etc všechny soubory s názvem začínajícím na a, n nebo v a končícím číslicí. rm /etc/[anv]*[0-9] 36. Napište příkaz, kterým přeložíte soubor prog.c a dále napište, jak se bude jmenovat výstupní soubor. cc prog.c a.out cc prog.c -o program výstupní soubor – program spuštění programu -./program 37. Napište příkaz, kterým pomocí příkazů ls a grep vypíšete podadresáře v adresáři /etc. ls -l /etc | grep '^d' ls -l /etc | grep '^d' | awk '{print: $9}' 38. Zadán příkaz: chmod 2446 x (nebo tak nějak) Napište, jaká práva a s- a t-bity příkaz nastaví. r--r-Srw- 39. Obsah řádkového souboru ~/a je Praha London Paris Hamburg 2712005 TIME = 14:30 moon sun mars Jaký výpis se vypíše a) grep “London” ~/a 1 řádek b) grep ar ~/a 1,3 řádek c) grep ‘^m’ ~ /a 3 řádek 40. Příklad fork if (fork()==0) pause(); fork(); pause(); fork(); 3xzablokovaný 41. Příkaz Umask řešení. S jakými přístupovými právy je vytvořen soubor, který má po použití následující masky tvar rwxr-xrwx: 111 101 111= 757 a) UMASK 022 maska 000 010 010 ¬ maska 111 101 101 mode 111 101 111 mode and ¬maska 111 101 101 = 755 b) UMASK 020 = 757 c) UMASK 0777 = 0000 42. Co se stane, pokud proces spustí binární soubor s nastaveným s-bitem uživatele? EUID se změní na UID spuštěného souboru 43. Soubory: rt101.a, stx102.a, ttsxx.b.c, xst.a jaký bude výsledek když: a) rm [r-t]*.a - smaže rt101.a a stx102.a b) rm *.a - smaže rt101.a, stx102.a, xst.a c) echo * - vypíše vše d) echo \* - nevypíše nic 44. Ochrana souborů a I/O v Linuxu, princip ověřování práv, změna práv I/O zařízení jsou reprezentována řídícími soubory a proto jsou chráněna stejným mechanismem. Přístupová práva pro individuálního, skupinového vlastníka, ostatní. Práva r, w, x; S-bit uživatele a skupiny. Každý soubor (resp. adresář) má svého individuálního vlastníka a svého skupinového vlastníka. Při vytvoření souboru je jeho individuální vlastník nastaven na EUID a jeho skupinový vlastník na EGID procesu, který soubor vytvořil. Práva k souboru může měnit proces, jehož EUID se rovná buď UID individuálního vlastníka souboru nebo běží s právy superuživatele (tj. jeho EUID = 0). Mechanismus předávání přístupových práv je řízen dvěma bity: s-bitem uživatele a s-bitem skupiny, které úzce souvisí s přístupovými právy a také se spolu s nimi nastavují. 45. Kolik zůstane zablokovaných procesu ? if (fork()==0) fork(); pause(); fork(); fork(); pause(); (něčí pozn. - blok po if by mel byt uzavřený v závorkách, aby bylo zadání úplné správné, ale uznával, že je to odsazené. Pak je správná odpověď 6) 46. Internetová adresa 193.84.54.12. Jaká je adresa sítě, maska a broadcast adresa, pokud nejsou použité podsítě. Kolik počítačů může být v síti? (něčí pozn. - je to C sít, takže maska 255.255.255.0, adresa sítě 193.84.54.0, bcast 193.84.54.255 a může tam byt 256-2=254 počítačů) 47. Příklad na práva Něco podobnýho jako je následující příklad, je potřeba znát s-bit a t-bit. $ ls -l s tímto výsledkem: -rwxrw-r-t 2 novy student........ myfinder -rwsrw-r-T 1 dvorak pedagog data1 -rwsrw-r-x 1 novy pedagog data2 -rwSrw-r-x 1 novak student........ data3 (první pomlčka je složka d – directory, l – soft link, - - normální složka) T - t – bit nastaven ale není nastaveno právno na spuštění t – t – bit nastaven a je nastaveno I právo na spuštění 2 počet hardlinků 48. Zadáte následující sekvenci příkazů: mkdir ~/data cd data mkdir data1 cp /etc/passed ~/data/data1/hesla kolik bude hardlinku na adresáře data,data1 a na soubor hesla? Jakým příkazem lze počet hardlinku zobrazit? 3 data 2 data1 1 hesla hardlinky se zobrazí pomocí příkazu ls – l (druhý sloupec) 49. Podrobně popište, jakým způsobem přiděluje operační systém Unix procesům procesor. Jak se stanoví priorita procesů, které poběží a) v uživatelském módu b) v módu jádra Priorita procesu, které poběží v módu jádra je vždy záporná a pokud proces běží v módu jádra, jeho priorita se nemění. 50. Podrobně vysvětlete co je soft link a hard link. Jak vytvoříte v domácím adresáři hard link na soubor etc/passwd? ln /etc/passwd ~/passwd 51. Kolik zablokovaných procesů v systému zůstane, pokud přeložím a spustím následující program: main() { if (fork() == 0){ fork(); pause(); } fork(); fork(); pause(); } 6 zablokovaných procesů 52. Zadáváme příkazy v Bourne Shellu. Zadáte následující dva příkazy $cat x b.doc a.aoc aa.doc k a..doc a. abc $cat x | grep ` a\..` > ~ /new Jaky bude obsah souboru new? a.aoc aa.doc k a..doc 53. Vysvětlete, co se rozumí v Unixu připojováním systémů souborů a jak je provádí. K čemu slouží soubor /etc/fstab? Lze také připojit souborový systém z jiného počítače? /etc/fstab popisuje jednotlivé diskové svazky Ano – lze připojit souborový system z jiného počítače 54. Kolik zablokovaných procesů v systému zůstane, pokud přeložím a spustím následující program: main() { if (fork() == 0){ fork(); pause(); } fork(); pause(); fork(); } 4 zablokované procesy 55. Obsah souboru data je následující: A1 y.xz B2xy?xaayxbbz Xyabcd.z Xzxy Xxxzyyy. Xabydzx?! Jaký bude výsledek příkazu Cat data| grep ’x.y’ | grep ’^x..*z’ Předposlední – xxxzyyy 56. Obsah souboru data je následující: 1) a14b20.c31 2) bba.1.a1 3) ba.1.bac11 4 b333.a.47 Které řádky souboru data budou vypsány příkazem: a) grep ´a.*c´ data řádek 1, 3 b) grep ´b.*a´ data řádek 1, 4 c) grep ´^ba\.[a1]´ data řádek 3 57. Efektivní a reální vlastník Uživatel přistupuje k souborům pomocí procesů. Proces má svého UID (reální individuální vlastník) a své GID (skupinový individuální vlastník). Obě tyto Id jsou nastaveny podle tabulky uživatelů po úspěšném připojení uživatele. Kromě UID a GID udržuje OS pro každý proces ještě EUID a EGID.EUID se nazývá efektivní individuální vlastník procesu.EGID se nazývá efektivní skupinový vlastník procesu. EUID = UID a EGID = GID tyto identity zůstávají platné po celou dobu procesu. E se mění pouze tehdy, když proces spustí soubor s nastaveným s bitem. U souborů lze nastavit: s-bit uživatele s-bit skupiny Pokud proces spustí binární soubor (tj. binární program) s nastaveným s-bitem uživatele, efektivním individuálním vlastníkem procesu se stane individuální vlastník právě spuštěného souboru (tj. EUID procesu se změní na UID spuštěného souboru) Pokud proces spustí binární soubor (tj. binární program) s nastaveným s-bitem skupiny, efektivním skupinovým vlastníkem procesu se stane skupinový vlastník právě spuštěného souboru (tj. EGID procesu se změní na GID spuštěného souboru) t-bit (sticky bit) Pokud je u binárního programu nastaven t-bit, znamená to, že po spuštění a skončení běhu programu, OS neuvolní všechny programem používané stránky vnitřní paměti. Následné spuštění programu je potom rychlejší. Pokud je t-bit nastaven u adresáře, obvykle to znamená (např. Linux), že uživatelé mohou v adresáři vytvářet nové soubory, ale rušit mohou jen své soubory 58. Skript Program napsaný v shellu se nazývá skript.Skript se nepřekládá, ale je interpretován podshellem: Použití skriptů: pro nastavení počátečního prostředí OS a systémových programů (konfigurační soubory systémových programů obvykle začínají. , tj. jsou to tzv. skryté soubory) pro administrativní účely jak se vytvoří a příklad jednoduchého skriptu? #!/bin/bash cd ~ mkdir programy data Šikovný handout: http://dev.fyicenter.com/Interview-Questions/UNIX cp /bin/ls programy/vypis 58. Co je tabulka stránek a jak se využívá při převádeění logické na fyzickou Tabulka organizovná podle čísel stránek, každé stránce odpovídá jeden řádek, v řádku je uvedeno číslo rámu, který je operační system stránce přidělil Adresní jednotka provádí překlad adresy pomocí tabulky stránek OS systém udržuje pro každý proces tabulku stránek. Tím, že v tabulce stránek OS přiřadí stránce číslo rámu, rozhodne o tom, kde ve fyzické paměti bude stránka uložena. Aby překlad logické adresy na fyzickou byl rychlý, procesor použité řádky tabulky stránek ukládá do rychlé asociativní paměti, která se nazývá TLB cache. 59. Jaké informace si unix ukládá o procesech v tabulce a u-oblasti 1. tabulka procesů - o běžících procesech – číslo procesu, popis stavu procesu, descriptor údalosti, pole signal, ukazatel na tabulku stránek procesu, ukazatel do u-oblasti na disku 2. u-oblast – o reální a efektivním jménu uživatele a skupiny, aktuáílní adresář a kořenový adresář, tabulku deskriptorů, I/O parametry, oštření signáu, řídící terminal, výsledek a parametry volání systému 60. Priorita procesu při přidělování procesoru rozhoduje o něm scheduler, procesy vybírá z tabulky procesů podle priority, proces s vyšší prioritou má při spouštění přednost. Priorita je definována: každému procesu je přiřazeno celé číslo, procesům běžícím v uživatelském módu je přiřazeno nezáporné číslo, bude-li proces spuštěn v módu jádra, dostal se do stavu ready to run tak, že běžel v módu jádra, provedl algoritmus slep_on(event) a pak byl rpobuzen. Proces má tím větší prioritu, čím menší číslo n je mu přiřazeno. 61. Vznik procesu, kdo je vlastníkem procesů proces lze vytvořit pomocí služby fork. Zavoláním služby systém vytvoří nový proces, který je kopií původního procesu. Všechny v systému exitující procesy vznikly tímto způsobem, kromě procesu swapper, který vytvořilo po spuštění systému jádro systému. Volající proces je proces rodič (parent) a nově vzniklý potomek (dítě, child). Liší se jen v PID procesu (nový proces dostane jiné číslo kvůli jednoznačné identifikaci), v uživatelské oblasti se do místa záznamu výsledku volání služby systému zapíše rodiči PID potomka a potomku 0. Swapper – proces, který běží v módu jádra a v systému zajišťuje odkládání procesů na disk. Uživatel přistupuje k souborům pomocí procesů. Proces má svého individuálního vlastníka (UID) a skupinového vlastníka (GID).UID a GID je nastaveno v procesu login podle tabulky uživatelů po úspěšném připojení uživatele.Všechny procesy, které uživatel dále spustí tyto UID a GID dědí. 62. Hardlink a softlink Hard linkem se rozumí adresářová položka, tedy dvojice název_souboru, číslo i-uzlu Po vytvoření regulárního souboru existuje na něj jeden hardlink a sice z adresáře, ve kterém byl vytvořen. Po vytvoření adresáře existují na něj dva hardlinky: jeden z adresáře, ve kterém byl vytvořen a druhý z nově vytvořeného, dosud prázdného adresáře. Po vytvoření podadresáře se zvýší o 1 počet hardlinků na nadřazený adresář. Softlink - symbolický link či odkaz, je implementován jako soubor obsahující cestu. Lze ho vytvořit příkazem ln. Soft link je samostatný soubor a má svůj i-uzel. Výhoda – mohou odkazovat i na soubory a adresáře v jiných systémech souborů. Nevýhoda – zrušíme-li soubor, na který soft link odkazuje, systém to nezjistí a v sytému může být řada soft linků, které na nic neodkazují. 63. Jak se vypíše hodnota HISTSIZE b) Jak se změní hodnota HISTSIZE Vypsání $ echo $HISTSIZE Změnit hodnotu Change.bash_profile, add HISTSIZE=3000, export this variable to override one in /etc/profile, save file. 4 běží, 2 pause A) 2 B) 4 A) Vnitřní příkazy jsou součástí shellu (příklad: cd, cp, rm a podobné) zatímco vnější nejsou součástí a nelze je vyvolat pouze naps?

Use Quizgecko on...
Browser
Browser