Is there a built in way to get the ID of a slurm job when it is being run?
I can imagine determining the ID by parsing squeue and matching the ID to the hostname (e.g. socket.gethostname()
in python). Is there a better solution?
The job ID is assigned to the SLURM_JOB_ID
environment variable. So in Python, you would get it with
import os
print(os.environ["SLURM_JOB_ID"])
Note that even though the job id is an integer, the environment variable contains a character string so you will need to call the int()
function to convert it.