FIT2109 Chap.7 Command-Line Environments
Command-Line Environments
Command-Line Environments separates prompt control, hangup protection and persistent terminal sessions. Appending & puts a job in the background and returns the prompt, but it does not itself guarantee survival when an SSH connection drops. nohup protects a non-interactive command from the hangup signal, usually with output redirected to a log.
tmux preserves a terminal session that can be detached and reattached.
The right choice follows from interaction needs. A batch analysis that writes progress to a file can use hangup protection and logs. An editor or interactive program needs a persistent terminal if the user wants to return to the same live screen. In either case, plan observation and safe termination at launch time.
What this chapter covers
- 01
SSH connection lifetime versus remote process lifetime
- 02
Background execution that returns the current prompt
- 03
Hangup signals after a controlling session disappears
- 04
Non-interactive jobs protected by nohup and logs
- 05
Persistent terminal sessions created with tmux
- 06
Starting work inside the session that should preserve it
- 07
Working directory and environment at launch time
- 08
Progress checks, process identity and controlled termination
Worked example · free
Plan a durable remote batch job
- +1Identify that the job is non-interactive and must survive connection loss.
- +1Explain that plain backgrounding returns the prompt but does not itself protect against hangup.
- +1Use hangup protection and send ordinary output and diagnostics to a deliberate log destination.
- +1Launch from a verified working directory with explicit input and output paths.
- +1Record an unambiguous process identity or query so the job can be checked after reconnecting.
- +1Inspect the log immediately for configuration errors and later for progress.
- +1Name tmux as the alternative when returning to an interactive terminal is required.
Key terms
- Background job
- A process launched without occupying the shell prompt. Backgrounding does not by itself define behaviour after the controlling session ends.
- Hangup signal
- A signal associated with a terminal or session ending. Unprotected jobs may respond by terminating.
- Nohup
- A mechanism for running a command so it ignores the hangup signal, commonly combined with explicit output logging.
- Persistent terminal
- A server-side terminal session that can continue independently of one network connection and later be reattached.
- Process identity
- A reliable way to distinguish the intended running job from unrelated processes when checking status or stopping work.
- Progress log
- A file or stream that records enough current information to determine whether a non-interactive job is advancing or failing.
Command-Line Environments FAQ
Why is backgrounding not enough for a dropped connection?
Backgrounding returns the shell prompt but leaves the process associated with the session unless other protection is arranged. A later hangup can still affect it, so prompt control and connection survival are separate requirements.
When is nohup a good fit?
It fits a non-interactive command that should continue after disconnection and whose progress can be observed through logs or output files. Use explicit paths and check the log immediately after launch.
When is a persistent terminal better?
Choose it when you need to return to the same interactive terminal state, run a sequence of commands or inspect a live program. Start the actual work inside the session before detaching.
How can I tell whether a remote job survived?
Reconnect, identify the process unambiguously, inspect the expected progress log or output and verify recent advancement. The absence of a launch error is not proof that the job is still running correctly.
Assessment move
Create three disposable remote-style scenarios on a safe machine. First, launch a short command in the background and observe that the prompt returns. Second, launch a non-interactive command with hangup protection and explicit logging, then check its process and log from another shell.
Third, create a named persistent terminal session, start an interactive or long-running command inside it, detach, list the session and reattach. For each route, explain what happens to the job when the original shell exits and how progress is observed. Include the working directory and environment in the explanation.
Deliberately create the common error of opening a persistent session but launching the job later in an ordinary shell, then diagnose why the session cannot preserve that unrelated process. Practise conditional answers rather than claiming one mechanism is always best. Add a safe stop to each scenario and check the final status and output integrity afterward.
Compare an interactive editor with a batch transformation so the requirement, not the duration, determines the mechanism. Finally, write the lifecycle from launch through reconnection in complete sentences; this prepares the longer question form better than memorising isolated commands.
Working through Command-Line Environments in FIT2109? Sia is AskSia’s AI Computer Science tutor — ask any FIT2109 Command-Line Environments question and get a clear, step-by-step explanation grounded in how FIT2109 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.