---
name: "slurm_hostlist_create"
section: "3"
platform: "linux"
package: "libslurm-dev"
version: "20.11.7+really20.11.4-2+deb11u1"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/slurm_hostlist_create"
---

# slurm\_hostlist\_create(3)

Slurm host list support functions

## NAME

slurm\_hostlist\_create, slurm\_hostlist\_shift, slurm\_hostlist\_destroy - Slurm host list support functions

## SYNTAX

\#include \<slurm/slurm.h\>

hostlist\_t **slurm\_hostlist\_create** (\
\
 	char \**node\_list*\
 );

char \* **slurm\_hostlist\_shift** (\
\
 	hostlist\_t *host\_list*\
 );

void **slurm\_hostlist\_destroy** (\
\
 	hostlist\_t *host\_list*\
 );

## ARGUMENTS

- *node\_list*

  A list of nodes as returned by the **slurm\_job\_step\_create** functions. The returned value may include a simple range format to describe numeric ranges of values and/or multiple numeric values (e.g. "linux\[1-3,6\]" represents "linux1", "linux2", "linux3", and "linux6").

- *host\_list*

  A hostlist created by the **slurm\_hostlist\_create** function.

## DESCRIPTION

**slurm\_hostlist\_create** creates a database of node names from a range format describing node names. Use **slurm\_hostlist\_destroy** to release storage associated with the database when no longer required.

**slurm\_hostlist\_shift** extracts the first entry from the host list database created by the **slurm\_hostlist\_create** function.

**slurm\_hostlist\_destroy** releases storage associated with a database created by **slurm\_hostlist\_create** when no longer required.

## RETURN VALUE

**slurm\_hostlist\_create** returns the host list database or NULL if memory can not be allocated for the database.

**slurm\_hostlist\_shift** returns a character string or NULL if no entries remain in the database.

## EXAMPLE

\#include \<stdio.h\>\
 \#include \<hostlist.h\>\
 \#include \<slurm.h\>

int main (int argc, char \*argv\[\])\
 {\
\
 	hostlist\_t my\_hostlist;\
\
 	char \*hostnames, \*host;

	/\* generate a list of hostnames, possibly using a \*/\
\
 	/\*    slurm job step creation function \*/

	my\_hostlist = slurm\_hostlist\_create (hostnames);\
\
 	if (my\_hostlist == NULL) {\
\
 		fprintf (stderr, "No memory\\n");\
\
 		exit (1);\
\
 	}

	while ( (host = slurm\_hostlist\_shift(my\_hostlist)) ) {\
\
 		printf ("host = %s\\n", host);\
\
 		free(host);\
\
 	}

	slurm\_hostlist\_destroy (my\_hostlist) ;\
\
 	exit (0);\
 }

## NOTE

These functions are included in the libslurm library, which must be linked to your process for use (e.g. "cc -lslurm myprog.c").

## COPYING

Copyright (C) 2002-2006 The Regents of the University of California. Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). CODE-OCEC-09-009. All rights reserved.

This file is part of Slurm, a resource management program. For details, see \<https://slurm.schedmd.com/\>.

Slurm is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Slurm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

## SEE ALSO

[**slurm\_get\_job\_steps**(3)](/slurm_get_job_steps/3.md), [**slurm\_load\_jobs**(3)](/slurm_load_jobs/3.md), **[slurm\_load\_partitions(3)](/slurm_load_partitions/3.md)**
