Skip to content
This page was generated and translated with the assistance of AI. If you spot any inaccuracies, feel free to help improve it. Edit on GitHub

File Monitoring

The sd monitor command watches directories for file system activity and scans new or modified files in real time. This is the primary way to catch malware the moment it lands on disk, before it has a chance to execute.

Usage

bash
sd monitor [OPTIONS] [PATHS...]

If no paths are specified, sd monitor watches the current working directory.

Options

FlagShortDefaultDescription
--recursive-rtrueWatch directories recursively
--block-bfalseBlock file execution until scan completes (Linux only)
--daemon-dfalseRun in the background as a daemon process
--pid-fileWrite PID to specified file (implies --daemon)
--exclude-eGlob patterns to exclude (repeatable)
--log-fileWrite log output to file instead of stderr
--auto-quarantine-qfalseAutomatically quarantine detected threats
--eventsallComma-separated list of events to watch
--jsonfalseOutput events as JSON lines

Platform Mechanisms

PRX-SD uses the most capable file system API available on each platform:

PlatformAPICapabilities
Linuxfanotify (kernel 5.1+)System-wide monitoring, execute permission control, file descriptor passthrough
Linux (fallback)inotifyPer-directory watches, no blocking support
macOSFSEventsLow-latency recursive monitoring, historical event replay
WindowsReadDirectoryChangesWPer-directory async monitoring with completion ports

TIP

On Linux, sd monitor requires CAP_SYS_ADMIN capability (or root) to use fanotify. If unavailable, it automatically falls back to inotify with a warning.

Monitored Events

The following file system events trigger a scan:

EventDescriptionPlatforms
CreateA new file is createdAll
ModifyFile contents are writtenAll
CloseWriteFile closed after writing (avoids partial scans)Linux
DeleteA file is removedAll
RenameA file is renamed or movedAll
OpenA file is opened for readingLinux (fanotify)
ExecuteA file is about to be executedLinux (fanotify)

Filter which events trigger scans with --events:

bash
# Only scan on new files and modifications
sd monitor --events Create,CloseWrite /home

Blocking Mode

On Linux with fanotify, --block enables FAN_OPEN_EXEC_PERM mode. In this mode the kernel pauses process execution until PRX-SD returns a verdict:

bash
sudo sd monitor --block /usr/local/bin /tmp

WARNING

Blocking mode adds latency to every program launch in the monitored paths. Use it only on high-risk directories like /tmp or download folders, not on system-wide paths like /usr or /lib.

When a threat is detected in blocking mode:

  1. The file open/execute is denied by the kernel
  2. The event is logged with verdict BLOCKED
  3. If --auto-quarantine is set, the file is moved to the quarantine vault

Daemon Mode

Use --daemon to detach the monitor from the terminal:

bash
sd monitor --daemon --pid-file /var/run/sd-monitor.pid /home /tmp /var/www

Stop the daemon by sending SIGTERM:

bash
kill $(cat /var/run/sd-monitor.pid)

Or use sd daemon stop if running through the daemon manager. See Daemon for details.

Examples

bash
# Watch home and tmp directories
sd monitor /home /tmp

# Watch with automatic quarantine
sd monitor --auto-quarantine /home/downloads

# Block-mode on Linux for a sensitive directory
sudo sd monitor --block --auto-quarantine /tmp

# Exclude build artifacts and node_modules
sd monitor -e "*.o" -e "node_modules/**" /home/dev/projects

# Run as daemon with JSON logging
sd monitor --daemon --json --log-file /var/log/sd-monitor.json /home

# Monitor with specific events only
sd monitor --events Create,Modify,Rename /var/www

JSON Output

When --json is enabled, each event produces a single JSON line:

json
{
  "timestamp": "2026-03-21T10:15:32.456Z",
  "event": "CloseWrite",
  "path": "/tmp/payload.exe",
  "verdict": "malicious",
  "threat": "Win.Trojan.Agent-123456",
  "action": "quarantined",
  "scan_ms": 12
}

Next Steps

Released under the Apache-2.0 License.