# Background/Phantom process overview

A phantom process is a process that is initiated at a terminal
and detaches itself from that terminal for execution independent of
that terminal. It is processed as a background task and the results
display on the initiating terminal when the process is complete.

The phantom process scheduler is the background process
that handles the phantom jobs submitted using the z command from TCL. This process is usually started in the system-coldstart macro by the start.ss program.

*Phantom jobs* are started using the z command
from TCL.

A phantom job runs if there is an available phantom
port or line. If there is no phantom port or line available, the phantom
job is enqueued until one becomes available.

**For UNIX:** If the first available line does not have a PID, and a line number
was not specified with the x command, the next
available line is used.

The scheduler process sleeps until a
running job completes or until a new job enters the queue. When a
phantom job completes, it wakes the scheduler and logs itself off.
The process is now available for other phantom tasks.

When a
phantom job is executed:

- PCB frame is fetched from overflow for the phantom job.

- Item is written to the dm,jobs, file that indicates that the request is waiting in the queue.

- Item-ID of the jobs file item is attached to the end of the queue.

- Scheduler process is awakened if it is asleep.

- Scheduler checks the queue and reads the item from the jobs file that corresponds to the next item-ID in the queue. If a port is available, the scheduler:

- Updates the status of the item in the jobs file to running.

- Adds an item to the jobs file using the port number as the item-ID.

- Logs the phantom job on to the port.

When a phantom process has finished, the status in the jobs
file is updated to *logged off*. Next, the phantom
is awakened and workspace is returned to overflow.

When the
scheduler releases a phantom job back to overflow, the item whose
port number is the item-ID of the job is deleted from the jobs file.

The p option in the users file terminates phantom
processes, rather than forcing a sleep when a BASIC input, a file inconsistency, or any other error that prompts for input
is encountered.

## See also

- [clear-jobs command](https://d3codex.com/tcl/clear-jobs-command/)
- [end command (TCL commands)](https://d3codex.com/tcl/end-command-tcl-commands/)
- [job-status command](https://d3codex.com/tcl/job-status-command/)
- [jobs file](https://d3codex.com/systemfiles/jobs-file/)
- [list-jobs macro](https://d3codex.com/tcl/list-jobs-macro/)
- [logon command](https://d3codex.com/tcl/logon-command/)
- [phantom-reset command](https://d3codex.com/tcl/phantom-reset-command/)
- [phantom-status command](https://d3codex.com/tcl/phantom-status-command/)
- [Port number](https://d3codex.com/definitions/port-number/)
- [start.ss command](https://d3codex.com/tcl/start-ss-command/)
- [startsched command](https://d3codex.com/backgroundphantomprocess/startsched-command/)
- [stopsched command](https://d3codex.com/tcl/stopsched-command/)
- [system-coldstart macro](https://d3codex.com/tcl/system-coldstart-macro/)
- [tcl command](https://d3codex.com/tcl/tcl-command/)
- [tcls command](https://d3codex.com/tcl/tcls-command/)
- [u0010 user exit](https://d3codex.com/pickbasic-flashbasic/u0010-user-exit/)
- [users file](https://d3codex.com/systemfiles/users-file/)
- [z command (Background/Phantom process commands)](https://d3codex.com/backgroundphantomprocess/z-command-background-phantom-process-commands/)

---
Source: https://d3codex.com/backgroundphantomprocess/background-phantom-process-overview/ - part of the D3Codex reference.
