The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a...

48
Job Control The Unix Shell Job Control Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

Transcript of The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a...

Page 1: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Job Control

The Unix Shell

Job Control

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.

Page 2: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

shell

Job Control Introduction

Page 3: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

shell $$$$ wc –l *.pdb | sort | head -1

Job Control Introduction

Page 4: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

shell $$$$ wc –l *.pdb | sort | head -1

wc sort head

Job Control Introduction

Page 5: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

shell $$$$ wc –l *.pdb | sort | head -1

wc sort head

Job Control Introduction

Control programs while they run

Page 6: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

shell $$$$ wc –l *.pdb | sort | head -1

wc sort head

Job Control Introduction

Control programs while they run

processes

Page 7: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Job Control Introduction

Page 8: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Job Control Introduction

Page 9: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Job Control Introduction

Page 10: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

Job Control Introduction

Page 11: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

Page 12: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

Process ID (unique at any moment)

Page 13: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

Parent process ID

Page 14: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

Parent process ID

What process created this one?

Page 15: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

Process group ID

Page 16: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

What terminal (TTY) is it running in?

Page 17: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

What terminal (TTY) is it running in?

'?' indicates a system service (no TTY)

Page 18: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

The user ID of the process's owner

Page 19: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

The user ID of the process's owner

Controls what the process can read, write, execute, …

Page 20: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

When the process was started

Page 21: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

A process is a running program

Some are yours

Most belong to the operating system (or other users)Most belong to the operating system (or other users)

Use ps to get a list

$$$$ ps

PID PPID PGID TTY UID STIME COMMAND

2152 1 2152 con 1000 13:19:07 /usr/bin/bash

Job Control Introduction

2276 2152 2276 con 1000 14:53:48 /usr/bin/ps

$$$$

The program the process is executing

Page 22: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Can stop, pause, and resume running processes

Job Control Introduction

Page 23: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Can stop, pause, and resume running processes

$$$$ ./analyze results*.dat

Job Control Introduction

Page 24: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

Job Control Introduction

Page 25: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$

Job Control Introduction

Page 26: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$

Stop the running program

Job Control Introduction

Page 27: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$

Job Control Introduction

Page 28: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$

Run in the background

Job Control Introduction

Page 29: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$

Run in the background

Shell returns right away instead

Job Control Introduction

Shell returns right away instead

of waiting for the program to finish

Page 30: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$

Can run other programs in the foreground

while waiting for background process(es) to finish

Job Control Introduction

while waiting for background process(es) to finish

Page 31: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$

Job Control Introduction

$$$$

Page 32: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$

Show background processes

Job Control Introduction

$$$$

Page 33: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$ fg

Job Control Introduction

$$$$ fg

Page 34: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$ fg Bring background job to foreground

Job Control Introduction

$$$$ fg Bring background job to foreground

Page 35: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$ fg Bring background job to foreground

Job Control Introduction

$$$$ fg Bring background job to foreground

Use fg %1, fg %2, etc. if there are

several background jobs

Page 36: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

$$$$ ./analyze results*.dat

...a few minutes pass...

Can stop, pause, and resume running processes

...a few minutes pass...

^C

$$$$ ./analyze results*.dat &

$$$$ fbcmd events

$$$$ jobs

[1] ./analyze results01.dat results02.dat results03.dat

$$$$ fg

Job Control Introduction

$$$$ fg

...a few minutes pass...

$$$$ And finally it's done

Page 37: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

Job Control Introduction

Page 38: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Job Control Introduction

Page 39: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background jobOr bg to resume it as a background job

Job Control Introduction

Page 40: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background job

$$$$ ./analyze results01.dat

Or bg to resume it as a background job

Job Control Introduction

Page 41: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background job

$$$$ ./analyze results01.dat

^Z

[1] Stopped ./analyze results01.dat

$$$$

Or bg to resume it as a background job

Job Control Introduction

Page 42: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background job

$$$$ ./analyze results01.dat

^Z

[1] Stopped ./analyze results01.dat

$$$$ bg %1

$$$$

Or bg to resume it as a background job

Job Control Introduction

$$$$

Page 43: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background job

$$$$ ./analyze results01.dat

^Z

[1] Stopped ./analyze results01.dat

$$$$ bg %1

$$$$ jobs

Or bg to resume it as a background job

Job Control Introduction

$$$$ jobs

[1] ./analyze results01.dat

$$$$

Page 44: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Use ^Z to pause a program that's already running

fg to resume it in the foreground

Or bg to resume it as a background job

$$$$ ./analyze results01.dat

^Z

[1] Stopped ./analyze results01.dat

$$$$ bg %1

$$$$ jobs

Or bg to resume it as a background job

Job Control Introduction

$$$$ jobs

[1] ./analyze results01.dat

$$$$ kill %1

$$$$

Page 45: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Job control mattered a lot when users only had

one terminal window

Job Control Introduction

Page 46: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Job control mattered a lot when users only had

one terminal window

Less important now: just open another windowLess important now: just open another window

Job Control Introduction

Page 47: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

Job control mattered a lot when users only had

one terminal window

Less important now: just open another windowLess important now: just open another window

Still useful when running programs remotely

Job Control Introduction

Page 48: The Unix Shell - Software Carpentryfg to resume it in the foreground Or bg to resume it as a background job $$$$ ./analyze results01.dat ^Z [1] Stopped ./analyze results01.dat $$$$

August 2010

created by

Greg Wilson

August 2010

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.