Linux Shell 3 Processes and Jobs

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

netstat

-

fg command

- A background job can be resumed using the fg(foreground) command. - syntax: Simply pass fg the job number $ fg [PID]

Jobs

- A job is a series of one or more commands that can be connected by pipes. - Displays a list of suspended jobs and jobs running in the background - By default, the jobs command lists only currently running jobs for the owner's specific shell. - Each command maintains its own process id - You can have only one foreground job in a window or on a screen, but you can have many background jobs.

background processes

- A program that is not blocking user interaction with the shell is said to be "in the background." - In a typical Linux installation, most applications are running in the background (e.g., a web server process). - To force a command to run in the background, use the special character & (ampersand). - If you wish to suspend a job (not the same as running it in the background!), you may use control-z (^Z) to temporarily suspend the current job and access a shell. - Note: some commands - including most interactive games - place the terminal in "raw" mode, allowing them to use the ^Z key combination for an alternative purpose.

Process

- An instance of a command currently being executed. - A process contains the code and information about its current activity. - PID, TTY, time, last command - All processes can be uniquely identified by a Process ID (PID). - The 'ps' command can be used to list processes. - The -t option shows processes associated with a specified terminal. Use the who command to identify your current tty.

background jobs

- If you wish to terminate a job that is currently running in the background, you cannot use ^C. - When you run a command in the background, you do not have to wait for the command to finish before running another command. - By running more than one job at a time, you are using one of Linux's important features: multitasking. - Running a command in the background can be useful when the command will run for a long time and does not need supervision. - It leaves the screen free so you can use it for other work. - To run a job in the background, type an ampersand (&) just before the RETURN that ends the command line. ex: $ cat a.txt & $ - When the background job finishes, the shell displays a message giving both the job number and the command line used to run the command. - You can resume the job using fg and then use ^C, or you can use the kill command with the appropriate job number ex: $ fg 1 (executes cat command) then ^C ex: $ kill %2

bg command

- Once you have suspended a job with ^Z, you can use the bg command to place a job in the background.

kill: Aborting a Background Job

- The interrupt key (usually CONTROL-C) cannot abort a background process; you must use kill (page 729) for this purpose. - Follow kill on the command line with either the PID number of the process you want to abort or a percent sign (%) followed by the job number. $ tail -f outfile & [1] 18228 $ ps | grep tail 18228 pts/4 00:00:00 tail $ kill 18228 [1]+ Terminated tail -f outfile or $kill %1

kill builtin vs utility

- The kill utility ( /bin/kill ) should not be confused with the kill builtin. While... $ kill %1 ...will likely terminate a job, you cannot be certain that... $ /bin/kill %1 ...will on many Unix and Linux systems.

foreground jobs

- When you run a command in the foreground, the shell waits for it to finish before displaying another prompt and allowing you to continue.

Moving a Job from the Foreground to the Background

- You can suspend a foreground job (stop it from running without aborting the job) by pressing the suspend key, usually CONTROL-Z. - The shell then stops the process and disconnects standard input from the keyboard. - You can put a suspended job in the background and restart it by using the bg command followed by the job number. - You do not need to specify the job number when there is only one stopped job. - Only the foreground job can take input from the keyboard. To connect the keyboard to a program running in the background, you must bring it to the foreground. To do so, type fg without any arguments when only one job is in the background. - When more than one job is in the background, type fg, or a percent sign (%), followed by the number of the job you want to bring into the foreground. - The shell displays the command you used to start the job (promptme in the following example), and you can enter any input the program requires to continue: $ fg 1 promptme - Redirect the output of a job you run in the background to keep it from interfering with whatever you are working on in the foreground (on the screen).

builtins

- a utility (also called a command) that is built into a shell. - Some commands are not run by the shell, but rather internal to it. - The shell always executes a shell builtin before trying to find a command or utility with the same name. - Builtins do not get their own forked process, and therefore execute faster. - Each shell has its own set of builtins that may work slightly differently. - To display a list of bash builtins, give the command info bash and select the Shell Builtin Commands menu. - Because bash was written by GNU, the info page has better information than does the man page. Look at example of using command "echo -e" from lesson 18 slides page 10


Ensembles d'études connexes

Module 23: Electric Potential Energy and Electric Potential

View Set

ACC202 Intermediate Accounting II Chapter 14 Smartbook

View Set

ATI Urinary Elimination - practice assessment

View Set

Chapter 33: Alterations in Cognition and Mental Health

View Set