-
Notifications
You must be signed in to change notification settings - Fork 1
/
05_bash_examples.txt
58 lines (44 loc) · 1.06 KB
/
05_bash_examples.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 5. Job Control
# Running processes in the background
# Start a sleep and interrupt it
sleep 30
# Ctrl-C
# Start a sleep
sleep 50
# Suspend current job
# Ctrl-Z
# Background that job
set +e
bg
# Bring it back into the foreground
fg
# Ctrl-C
# Make new sleep job and put in the background
sleep 120 &
# Bring sleep job back to foreground
fg 1
# Ctrl-C
set -e
# Processes
# List running processes in current shell
ps
# List all processes belonging to you running on this machine
ps -u
ps -uf
# List all processes
ps -a
ps -af
# Start a sleep process in the background, grab it's process id
# (last PID is stored in $!), then kill it and confirm it is dead
sleep 600 &
pid=$!
echo "Sleep process pid = $pid"
ps
kill $!
ps
# Kill sends signals to processes, which they can choose to ignore.
# Can specify the signal to send, and "kill -9" will kill just about
# anything, but may prevent graceful cleanup
# tmux is quite advanced, but beyond the scope of this lesson except
# to say it is useful if you need to resume your work between different
# physical locations