#include <stdio.h>
#include <stdlib.h>

typedef struct Task {
	int id;
	struct Task *next;
} Task;

void printProcesses(Task *first) {
	if (first) {
		printf("%d\n", first->id);
		printProcesses(first->next);
	}
}
Task *createOneProcess() {
	static int nextTaskID = 1;
	Task *tt = (Task *)malloc(sizeof(Task));
	tt->next = NULL;	// not required, but for safety.
	tt->id = nextTaskID++;	// Exchanging these two (this and above) lines may remove the segfault.
	return tt;
}
Task *createProcesses(int N) {
	if (N == 0) return NULL;
	Task *proc = createOneProcess();
	proc->next = createProcesses(N - 1);
	return proc;
}
void deleteProcesses(Task *first) {
	if (first) {
		deleteProcesses(first->next);
		free(first);
	}
}
int main() {
	int N = 10;
	Task *first = createProcesses(N);
	printProcesses(first);
	deleteProcesses(first);

	return 0;
}
