#!/bin/bash #SBATCH -p IFIall # partition (queue) #SBATCH --nodes 8 # number of nodes #SBATCH --cores 1 # number of cores #SBATCH --ntasks-per-node=1 #SBATCH --account=dbis #SBATCH --mem 100 # memory pool for all cores #SBATCH -t 0-2:00 # time (D-HH:MM) #SBATCH -o slurm.%N.%j.out # STDOUT #SBATCH -e slurm.%N.%j.err # STDERR /bin/cat < sample.c // C program to display hostname // and IP address #include #include #include #include #include #include #include #include #include // Returns hostname for the local computer void checkHostName(int hostname) { if (hostname == -1) { perror("gethostname"); exit(1); } } // Returns host information corresponding to host name void checkHostEntry(struct hostent * hostentry) { if (hostentry == NULL) { perror("gethostbyname"); exit(1); } } // Converts space-delimited IPv4 addresses // to dotted-decimal format void checkIPbuffer(char *IPbuffer) { if (NULL == IPbuffer) { perror("inet_ntoa"); exit(1); } } // Driver code int main() { char hostbuffer[256]; char *IPbuffer; struct hostent *host_entry; int hostname; // To retrieve hostname hostname = gethostname(hostbuffer, sizeof(hostbuffer)); checkHostName(hostname); // To retrieve host information host_entry = gethostbyname(hostbuffer); checkHostEntry(host_entry); // To convert an Internet network // address into ASCII string IPbuffer = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); printf("Hostname: %s\n", hostbuffer); printf("Host IP: %s\n", IPbuffer); return 0; } EOM gcc -o sample sample.c srun sample