Skip to content

Interactive Jobs

Exercises

  1. Get an interactive shell with srun

Use srun to start an interactive bash session on a compute node with 2 CPUs, 4G of memory, and a 30-minute time limit. Once on the node, confirm you are not on the login node by running hostname, then exit cleanly.

Hint / Solution
srun --pty --cpus-per-task=2 --mem=4G --time=00:30:00 bash

# On the compute node:
hostname       # Should show a compute node name, not the login node
nproc          # Should show at least 2
exit           # Release the allocation
  1. Allocate resources with salloc, then run commands

Use salloc to reserve 4 CPUs and 8G of memory for 1 hour. Then use srun within that allocation to run hostname and free -m on the allocated node. Release the allocation when done.

Hint / Solution
salloc --cpus-per-task=4 --mem=8G --time=01:00:00

# You're still on the login node but have reserved resources
srun hostname
srun free -m

# Release
exit
  1. Request X11 forwarding for a graphical application

First, SSH to the cluster with X11 forwarding enabled. Then use srun with --x11 to start an interactive session. Verify X11 is working by running xeyes or xclock (if available), or by checking that the $DISPLAY environment variable is set.

Hint / Solution
# From your local machine:
ssh -X username@cluster.example.com

# On the login node:
srun --pty --x11 --time=00:30:00 --mem=4G bash

# On the compute node, verify X11:
echo $DISPLAY       # Should be set (e.g., localhost:10.0)
xclock &            # Should open a clock window on your display
exit
  1. Run a single command on a compute node without an interactive shell

Use srun (without --pty or bash) to run a single command on a compute node. Check which Linux kernel version is running on the compute nodes by executing uname -a.

Hint / Solution
srun --time=00:05:00 uname -a
This runs the command on a compute node and prints the result directly to your terminal without starting an interactive session.

References