Warm tip: This article is reproduced from serverfault.com, please click

slurm get job id within bash

发布于 2020-11-28 03:41:24

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?

Questioner
Tim
Viewed
0
damienfrancois 2020-11-30 02:59:31

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.