#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

static void burn_cpu(void)
{
    volatile unsigned long long x = 0;

    while (1) {
        x++;
    }
}

int main(void)
{
    long cpu_count = sysconf(_SC_NPROCESSORS_ONLN);

    if (cpu_count < 1) {
        perror("sysconf");
        return EXIT_FAILURE;
    }

    printf("Starting %ld CPU workers\n", cpu_count);

    for (long i = 0; i < cpu_count; i++) {
        pid_t pid = fork();

        if (pid < 0) {
            perror("fork");
            return EXIT_FAILURE;
        }

        if (pid == 0) {
            burn_cpu();
            return EXIT_SUCCESS;
        }
    }

    while (wait(NULL) > 0) {
    }

    return EXIT_SUCCESS;
}
