Reasons to use your shell's job control
Job control in a shell environment offers benefits like managing processes in foreground, background, or stopped states. Commands like fg, bg, Ctrl+z, and kill are explained for process manipulation. Users can kill unresponsive processes, background GUI apps, manage long-running jobs, test commands, and organize output efficiently.
Read original articleThe article discusses the benefits of using job control in a shell environment interactively. Job control allows users to manage processes in the foreground, background, or stopped states. Commands like fg, bg, Ctrl+z, jobs, kill, disown, and wait are explained for manipulating processes. Reasons for using job control include killing unresponsive processes, backgrounding GUI apps, managing long-running jobs, testing commands while using editors like vim, and organizing interleaved output. Job control can also be useful for suspending CPU-intensive tasks, recovering accidentally stopped programs, maintaining environment variables, and when it's the only available option. Different perspectives on job control usage are shared, highlighting preferences for terminal visibility and managing multiple processes efficiently. The article concludes with the author's intention to explore job control further for specific tasks like killing unresponsive processes and running network commands alongside tools like tcpdump.
Related
FreeBSD Bhyve Companion Tools
The author details transitioning from VirtualBox to FreeBSD Bhyve, praising Bhyve's benefits in a FreeBSD setting. Tools like VNC connection and pause/resume scripts optimize Bhyve operations, simplifying VM management.
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
Htop explained – everything you can see in htop on Linux (2019)
This article explains htop, a Linux system monitoring tool. It covers uptime, load average, processes, memory usage, and more. It details htop's display, load averages, process IDs, procfs, and process tree structure. Practical examples are provided for system analysis.
FullBashGuide
The FullBashGuide on Greg's Wiki offers a comprehensive resource for beginners to learn BASH scripting. It covers commands, parameters, arrays, job control, and stresses testing code and proper quoting practices.
Four lines of code it was four lines of code
The programmer resolved a CPU utilization issue by removing unnecessary Unix domain socket code from a TCP and TLS service handler. This debugging process emphasized meticulous code review and system interaction understanding.
https://en.wikipedia.org/wiki/ADM-3A
It is unfortunate that Bill Joy was both the first and last word in job control (even as his csh has been largely abandoned), as this functionality has been copied first into the Korn shell, then into the POSIX shell, and hasn't seen any substantial improvement since the 1970s.
It would be very helpful if shell job control could address available processors (and become aware of asymmetric big/LITTLE configurations), hold jobs until CPUs become available, and keep a list of failed jobs for retry.
The standards will likely never implement this functionality. This is the fault of the Austin Group.
I would add that as a shortcut, you can just type % (without fg) to foreground the current job, or % and a number to foreground a particular job. (In Bash, anyway.)
I use tmux, but I often use job control as an extra dimension, having several jobs in any given tmux window. (Yes, this leads to the inevitable "There are stopped jobs." warning when I attempt to exit a shell/window, which makes cleanup slightly more tedious.)
It will prevent the process from getting SIGHUP when the terminal is closed, but it won't change the pty or stdin/stdout/stderr of the process, so it may still abort if/when I/O is performed. Using e.g. nohup solves this problem more completely. If you see programs abort even with disown, they are probably aborting on I/O errors to the terminal.
Also, some terminals (e.g. kitty) will not auto-close when bash exits if there are still processes having the PTY open. Here's a simple example to play around with to see some different possibilities (and check how your shell handles things). NB: It runs "exit" at the end, so run in a fresh terminal window/tab
{ set -e; rm -f /tmp/got-here; sleep 5; echo hi; touch /tmp/got-here; } 2>/tmp/test-stderr & disown; exit
If you run this in a terminal that doesn't close when your shell exits if any other process still has the pty open, then the tab/window will hang around for 5 seconds and then disappear; /tmp/got-here will exist. If you run in a terminal that does close when your shell exits (e.g. xterm), then /tmp/got-here will never be created and you'll see an IO error message in /tmp/test-stderrRelated
FreeBSD Bhyve Companion Tools
The author details transitioning from VirtualBox to FreeBSD Bhyve, praising Bhyve's benefits in a FreeBSD setting. Tools like VNC connection and pause/resume scripts optimize Bhyve operations, simplifying VM management.
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
Htop explained – everything you can see in htop on Linux (2019)
This article explains htop, a Linux system monitoring tool. It covers uptime, load average, processes, memory usage, and more. It details htop's display, load averages, process IDs, procfs, and process tree structure. Practical examples are provided for system analysis.
FullBashGuide
The FullBashGuide on Greg's Wiki offers a comprehensive resource for beginners to learn BASH scripting. It covers commands, parameters, arrays, job control, and stresses testing code and proper quoting practices.
Four lines of code it was four lines of code
The programmer resolved a CPU utilization issue by removing unnecessary Unix domain socket code from a TCP and TLS service handler. This debugging process emphasized meticulous code review and system interaction understanding.