on 19-Oct-2018 (Fri)

Flashcard 3433786117388

Question
In linux, you have a file called test.txt, how do you replace only the first occurence of "GNU", on each line in that file, with "NGU"? You can have this output just go to prompt/stdout (no need to capture it in new file).
sed -e 's/GNU/NGU/' test.txt
^^ note the -e is needed (e for expression)
^^ note that the last / in the 's/regex/replace/' is not followed by anything, i.e. not followed by g, to indicate replacing only the first instance found, not all instances

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
\ > <resultfile> where <search-regexp> is a regular expression, <replace-text> is the text you would like to replace each occurrence with, and <option> is nothing or <span>g , which means to replace every occurrence in the same line (usually sed just replaces the first occurrence of the regular expression in each line). (There are other <option> ; see

Flashcard 3442072227084

Question
In linux, regular expression [...] , marked via the enclosing escaped-round-bracket syntax, group parts of a regular expression together, so they can be swapped or just displayed in chuncks via sed, for example.
subexpressions

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
g text around within lines. Consider, for example, the output of ls : say you want to automatically strip out only the size column-- sed can do this sort of editing if you use the special  <span>notation to group parts of the regular expression together. Consider the following example: sed -e 's/$$<[^ ]*>$$$$[ ]*$$$$<[^ ]*>$$/\3\2\1/g' Here sed is searching for the expression \<.*\>[ ]*\<.*\> . From the chapter

Flashcard 3442091625740

Question
In linux, running the command: du -h test.sh , for example, produces the following output:
4.0K test.h
Run a command from the shell such that the above output is printed in reverse, i.e. :
test.h 4.0K
** note: in du output is seperated by tabs (so use \t in your regex not spaces)
du -h test.sh | sed -e 's/$$\<.*\>$$$$\t*$$$$\<.*\>$$/\3 \1/g'
^^ note: the use of chuncking the regex in to 3 regex subexpressions via the backslash-paranthesis syntax
^^ note: the use of the \<\> syntax to signify whole words
^^ note the use of \3 \1 in the replacement clause to do the actual swapping.

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
't yet figured it out, we are trying to get that column of byte sizes into a format like + 438 + 1525 + 76 + 92146 so that expr can understand it. Hence, we replace each line with subexpression <span>\2 and a leading + sign. Backquotes give the output of this to expr , which studiously sums them, ignoring any newline characters as though the summation were typed in on a single line. There is one minor

Flashcard 3442141957388

Question
In linux, you have file, test.txt, how do you insert "hello there" before every line that has the string "test" in it (where the new output is sent only to stdout, i.e. the file itself is not changed)?
sed -e '/test/i \
hello there' test.txt
^^ note the /regex/i syntx, the \ line seperator and all else:)

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
rting from a line matching the regular expression Dear Henry up to a line matching Love Jane (or the end of the file if one does not exist). This behavior applies just as well to to insertions: <span>sed -e '/Love Jane/i\ Love Carol\ Love Beth' Note that the $symbol indicates the last line: sed -e '$i\ The new second last line\ The new last line.' and finally, the negation symbol, ! , is used to match

Flashcard 3442145627404

Question
In linux, use sed to insert the line "hello there" at the end (i.e. AFTER last line) of file, test.txt, where output is just sent to stdout.
sed -e '$a \ hello there' test.txt ^^ note the use of the$a syntax to insert after last line

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
(or the end of the file if one does not exist). This behavior applies just as well to to insertions: sed -e '/Love Jane/i\ Love Carol\ Love Beth' Note that the $symbol indicates the last line: <span>sed -e '$i\ The new second last line\ The new last line.' and finally, the negation symbol, ! , is used to match all lines not specified; for instance, sed -e '7,11!D' deletes all lines except line

Flashcard 3442169220364

Question
In linux, native programs like ls, rm, etc, are usually stored in the [...] directory
/bin

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
offee first. 9.1 Introduction On UNIX, when you run a program (like any of the shell commands you have been using), the actual computer instructions are read from a file on disk from one of the <span>bin/ directories and placed in RAM. The program is then executed in memory and becomes a process. A process is some command/program/shell-script that is being run (or executed) in memory. Wh

Flashcard 3442172890380

Question
In Linux, non-native programs, such as user installed programs (e.g. git, docker, etc) and non-native programs that are usually there on the system by default (e.g. python), are stored in the [...] directory
/usr/bin

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ee first. 9.1 Introduction On UNIX, when you run a program (like any of the shell commands you have been using), the actual computer instructions are read from a file on disk from one of the bin<span>/ directories and placed in RAM. The program is then executed in memory and becomes a process. A process is some command/program/shell-script that is being run (or executed) in memory. Wh

Flashcard 3442176036108

Question
In linux, a [...] is some command/program/shell-script that is being run (or executed) in memory
process

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
have been using), the actual computer instructions are read from a file on disk from one of the bin/ directories and placed in RAM. The program is then executed in memory and becomes a process. <span>A process is some command/program/shell-script that is being run (or executed) in memory. When the process has finished running, it is removed from memory. There are usually about 50 processes running simultaneously at any one time on a system with one person logged in. The

Flashcard 3442179181836

Question
In linux, each process is given a process number called the [...]
PID (process ID)

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ions of a particular program. Note this is in contrast to Windows or DOS where the program itself has to allow the others a share of the CPU: under UNIX, the process has no say in the matter. ] <span>Each process is given a process number called the PID (process ID). Besides the memory actually occupied by the executable, the process itself seizes additional memory for its operations. In the same way that a file is owned by a particular user and gr

Flashcard 3442182327564

Question
In linux, all processes have an owner (by which the process' access to files it wants to access are determined), the process owner is the [...] .
user who ran the program.

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
lly occupied by the executable, the process itself seizes additional memory for its operations. In the same way that a file is owned by a particular user and group, a process also has an owner--<span>usually the person who ran the program. Whenever a process tries to access a file, its ownership is compared to that of the file to decide if the access is permissible. Because all devices are files, the only way a process ca

Flashcard 3442185473292

Question
In linux, whenever a process tries to access a file (or any device/etc, since everything in linux is a file), access is granted/denied by comparing the permissions of the process [...] to that of the file
owner

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ess itself seizes additional memory for its operations. In the same way that a file is owned by a particular user and group, a process also has an owner--usually the person who ran the program. <span>Whenever a process tries to access a file, its ownership is compared to that of the file to decide if the access is permissible. Because all devices are files, the only way a process can do anything is through a file, and hence file permission restrictions are the only kind of restrictions ever needed on UNIX. [

Flashcard 3442188619020

Question
In linux, you run the [...] command to see the list of all running processes
ps

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ctually does the hardware access, execution, allocation of process IDs, sharing of CPU time, and ownership management. 9.2 ps -- List Running Processes Log in on a terminal and type the command <span>ps . You should get some output like: PID TTY STAT TIME COMMAND 5995 2 S 0:00 /bin/login -- myname 5999 2 S 0:00 -bash 6030 2 R 0:00 ps ps with no options shows three processes to be runni

Flashcard 3442191764748

Question
In linux, for the ps command, ps stands for [...] [...]
process status

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
nning Processes Log in on a terminal and type the command ps . You should get some output like: PID TTY STAT TIME COMMAND 5995 2 S 0:00 /bin/login -- myname 5999 2 S 0:00 -bash 6030 2 R 0:00 ps <span>ps with no options shows three processes to be running. These are the only three processes visible to you as a user, although there are other system processes not belonging to you. The fir

Flashcard 3442194910476

Question
In linux, which shell is the shell that you type commands in when you login
bash

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ystem processes not belonging to you. The first process was the program that logged you in by displaying the login prompt and requesting a password. It then ran a second process call bash , the <span>Bourne Again shell [The Bourne shell was the original UNIX shell] where you have been typing commands. Finally, you ran ps , which must have found itself when it checked which processes were running, but

Flashcard 3442198056204

Question
In linux, bash stands for [...]
Bourne Again Shell
^^ Note: Bourne was the shell of Unix, so that is where Bourne Again comes from

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
nging to you. The first process was the program that logged you in by displaying the login prompt and requesting a password. It then ran a second process call bash , the Bourne Again shell [The <span>Bourne shell was the original UNIX shell] where you have been typing commands. Finally, you ran ps , which must have found itself when it checked which processes were running, but then exited

Flashcard 3442201201932

Question
In linux, what keyboard shortcut do you type at the shell to stop a running process (note I said stop not kill/terminate).
ctrl-z

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
script called proc.sh : #!/bin/sh echo "proc.sh: is running" sleep 1000 Run the script with chmod 0755 proc.sh and then ./proc.sh . The shell blocks, waiting for the process to exit. Now press <span>^Z. This will cause the process to stop (that is, pause but not terminate). Now do a ps again. You will see your script listed. However, it is not presently running because it is in the co

Flashcard 3442204347660

Question
In linux, the [...] command will resume stopped/suspended jobs and run them in the background
bg

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
rocess to stop (that is, pause but not terminate). Now do a ps again. You will see your script listed. However, it is not presently running because it is in the condition of being stopped. Type <span>bg (for background). The script will now be unstopped'' and run in the background. You can now try to run other processes in the meantime. Type fg , and the script returns to the foregro

Flashcard 3442206182668

Question
In linux, the shell has many facilities for controlling and executing processes--this is called [...] control
job

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
where you have been typing commands. Finally, you ran ps , which must have found itself when it checked which processes were running, but then exited immediately afterward. 9.3 Controlling Jobs <span>The shell has many facilities for controlling and executing processes--this is called job control. Create a small script called proc.sh : #!/bin/sh echo "proc.sh: is running" sleep 1000 Run the script with chmod 0755 proc.sh and then ./proc.sh . The shell blocks, waiting for the pro

Flashcard 3442211425548

Question
In linux, the [...] command will resume stopped/suspended jobs and run them on the current shell and it can also just bring a process running in the background into the foreground.
fg

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
e it is in the condition of being stopped. Type bg (for background). The script will now be unstopped'' and run in the background. You can now try to run other processes in the meantime. Type <span>fg , and the script returns to the foreground. You can then type ^C to interrupt the process. 9.4 Creating Background Processes Create a program that does something a little more interesti

Flashcard 3442213784844

Question
In linux, for the fg and bg commands (to resume stopped jobs in the foreground/background), if you do not specify a specific job when you run these commands, what job(s) is resumed?
The last job that was stopped

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
e it is in the condition of being stopped. Type bg (for background). The script will now be unstopped'' and run in the background. You can now try to run other processes in the meantime. Type <span>fg , and the script returns to the foreground. You can then type ^C to interrupt the process. 9.4 Creating Background Processes Create a program that does something a little more interesting

Flashcard 3442219814156

Question
In linux, let's say you have a program called "test" that you want to run from the shell, issue command to run it in the background.
test &

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
c.sh: is running" while true ; do echo -e '\a' sleep 2 done Now perform the ^Z, bg , fg , and ^C operations from before. To put a process immediately into the background, you can use: ./proc.sh <span>& The JOB CONTROL section of the bash man page ( bash (1)) looks like this (footnote follows) [Thanks to Brian Fox and Chet Ramey for this material.] : (the footnotes are mine) JOB CONTRO

Flashcard 3442224532748

Question
In linux, to terminate a process, you use the [...] command
kill

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
he jobs command to inspect their status. If you do this, or try to exit again immediately, you are not warned again, and the stopped jobs are terminated. 9.5 kill ing a Process, Sending Signals <span>To terminate a process, use the kill command: kill <PID> The kill command actually sends a termination signal to the process. The sending of a signal simply means that the process is asked to execute one of 30 predefined fun

Flashcard 3442227678476

Question
In linux, when you use the kill command to terminate a process, you can pass in options to specify the exact [...] to send to kill the process
signal

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
The default behavior for the termination signal is to terminate the process. To send a specific signal to a process, you can name the signal on the command-line or use its numerical equivalent: <span>kill -SIGTERM 12345 or kill -15 12345 which is the signal that kill normally sends when none is specified on the command-line. To unconditionally terminate a process: kill -SIGKILL 12345 or kill -9 12345 w

Flashcard 3442230824204

Question
In linux, you have process running with pid 12345, how do you terminate the process gracefully (i.e. you give program chance to clean up before it is terminated, if the programmer has implemented this)?
kill -SIGTERM 12345
^^^ note the -SIGTERM syntax to send the SIGTERM signal to kill the process gracefully
^^^ note above is equal to: kill -15 12345

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
The default behavior for the termination signal is to terminate the process. To send a specific signal to a process, you can name the signal on the command-line or use its numerical equivalent: <span>kill -SIGTERM 12345 or kill -15 12345 which is the signal that kill normally sends when none is specified on the command-line. To unconditionally terminate a process: kill -SIGKILL 12345 or kill -9 12345 w

Flashcard 3442233969932

Question
In linux, you have process running with pid 12345, how do you terminate the process forcefully (i.e. this is usually not recommended as it will not give program chance to terminate gracefully)?
kill -SIGKILL 12345
^^^ note the -SIGKILL syntax to send the SIGKILL signal to kill the process forcefully
^^^ note above is equal to: kill -9 12345

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
press ^C. SIGQUIT (3) Quit from keyboard. Issued if you press ^D. SIGFPE (8) Floating point exception. Issued automatically to a program performing some kind of illegal mathematical operation. <span>SIGKILL (9) Kill signal. This is one of the signals that can never be caught by a process. If a process gets this signal it must quit immediately and will not perform any clean-up operations (l

Flashcard 3442238688524

Question
In linux, cpu scheduling priority of a process is controlled by the kernel; but you can influence a process' cpu scheduling priority, when you first run the program, via the [...] command
nice

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ther process? How does the kernel tell? The answer is the UNIX feature of scheduling priority or niceness. Scheduling priority ranges from +20 to -20 . You can set a process's niceness with the <span>renice command. renice <priority> <pid> renice <priority> -u <user> renice <priority> -g <group> A typical example is the SETI program. [SETI stands for Sea

Flashcard 3442241834252

Question
In linux, cpu scheduling priority of a process is controlled by the kernel; but you can influence a process' cpu scheduling priority, after the process has already started running, via the [...] command
renice

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
the processes that a user or group owns. Further, we have the nice command, which starts a program under a defined niceness relative to the current nice value of the present user. For example, <span>nice +<priority> <pid> nice -<priority> <pid> Finally, the snice command can both display and set the current niceness. This command doesn't seem to work on my machin

Flashcard 3442245242124

Question
In linux, when you have a running process with pid 12345, issue command to get the kernel to give the most CPU scheduling priority to this process.
renice -20 12345
^^ note the -20, to indicate this is "not nice" process, i.e. it will have high cpu utalization.

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
process is doing some operation more important than another process? How does the kernel tell? The answer is the UNIX feature of scheduling priority or niceness. Scheduling priority ranges from <span>+20 to -20 . You can set a process's niceness with the renice command. renice <priority> <pid> renice <priority> -u <user> renice <priority> -g <group> A typica

Flashcard 3442249174284

Question
In linux, when you have a running prcess with pid 12345, issue command to get the kernel to give the least CPU scheduling priority to this process.
renice +20 12345

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
process is doing some operation more important than another process? How does the kernel tell? The answer is the UNIX feature of scheduling priority or niceness. Scheduling priority ranges from <span>+20 to -20 . You can set a process's niceness with the renice command. renice <priority> <pid> renice <priority> -u <user> renice <priority> -g <group> A

Flashcard 3442253368588

Question
In linux, if you want to see what process is hogging your system (i.e. using too much memory and/or CPU), what command do you issue?
top

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
on my machine. snice -v <pid> 9.8 Process CPU/Memory Consumption, top The top command sorts all processes by their CPU and memory consumption and displays the top twenty or so in a table. <span>Use top whenever you want to see what's hogging your system. top -q -d 2 is useful for scheduling the top command itself to a high priority, so that it is sure to refresh its listing without lag. top -n 1 -b > top.txt lists all processes, and

Flashcard 3442256514316

Question
In linux, what does the top command display?
It lists, in order, the top 20 processes, by CPU/memory usage.

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
t;pid> Finally, the snice command can both display and set the current niceness. This command doesn't seem to work on my machine. snice -v <pid> 9.8 Process CPU/Memory Consumption, top <span>The top command sorts all processes by their CPU and memory consumption and displays the top twenty or so in a table. Use top whenever you want to see what's hogging your system. top -q -d 2 is useful for scheduling the top command itself to a high priority

Flashcard 3442259660044

Question
In linux, if you are in the top program, what is the key to press to terminate a process?
k

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ult the only fields shown are USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND which is usually what you are most interested in. (The field meanings are given below.) r Renices a process. <span>k Kills a process. The top man page describes the field meanings. Some of these are confusing and assume knowledge of the internals of C programs. The main question people ask is: How muc

Flashcard 3442262805772

Question
In linux, if you are in the top program, what is the key to press to reprioritize the cpu scheduling priority of a process?
r
^^ r for renice

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
nteractively. By default the only fields shown are USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND which is usually what you are most interested in. (The field meanings are given below.) <span>r Renices a process. k Kills a process. The top man page describes the field meanings. Some of these are confusing and assume knowledge of the internals of C programs. The main question p

Flashcard 3442265951500

Question
In linux, the top program has the following headings:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
which of above have information about how much memory is being used by give process (aside from %MEM)
RES and SHR
^^^ RES stands for Resident Size, actual physical memory process is using
^^^ SHR stands for Shared memory

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
oken for ELF processes. TRS Text resident size. SWAP Size of the swapped out part of the task. D Size of pages marked dirty. LIB Size of use library pages. This does not work for ELF processes. <span>RSS The total amount of physical memory used by the task, in kilobytes, is shown here. For ELF processes used library pages are counted here, for a.out processes not. SHARE The amount of sh

Flashcard 3442269097228

Question
In linux, [...] [...] allow a process to have access to variable that it may have inherited from its parent process (or from any of its ancestor processes).
environment variables

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
ill only have the name of the program in parentheses (for example, "(getty)"). 9.9 Environments of Processes Each process that runs does so with the knowledge of several var = value text pairs. <span>All this means is that a process can look up the value of some variable that it may have inherited from its parent process. The complete list of these text pairs is called the environment of the process, and each var is called an environment variable. Each process has its own environment, which is copied fr

Flashcard 3442272242956

Question
In linux, the export command is used to add a variable to the list of the current process' environment variables (for example the shell's env variables, if shell is current process). Why is this useful?
So that any child process can also have access to that variable.

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
You will see that X is not set. The reason is that the variable was not export ed as an environment variable and hence was not inherited. Now type exit which breaks to the parent process. Then <span>export X bash echo $X You will see that the new bash now knows about X . Above we are setting an arbitrary variable for our own use. bash (and many other programs) automatically set many of th Flashcard 3442275388684 Question In linux, if I am in the bash shell, and I type: x=2 bash In the child bash process, I will not have access to x (i.e. I cannot get anything from:$x), unless I issue what command from the original parent shell?
export x

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
variable. But now run bash You have now run a new process which is a child of the process you were just in. Type echo $X You will see that X is not set. The reason is that the variable was not <span>export ed as an environment variable and hence was not inherited. Now type exit which breaks to the parent process. Then export X bash echo$X You will see that the new bash now knows about X

Flashcard 3442278534412

Question
In linux, issue command to get the list of all the current process' (i.e. the bash shell's) environment variables.
env
^^ or printenv

status measured difficulty not learned 37% [default] 0
9. Processes, Environment Variables
nment with environment variables. To get a complete list of these variables, just type: set This command is useful for finding the value of an environment variable whose name you are unsure of: <span>set | grep <regexp> Try set | grep PATH to see the PATH environment variable discussed previously. The purpose of an environment is just to have an alternative way of passing paramete

Flashcard 3442281680140

Question
In linux, environment variables always belong to the current [...]