Hey everyone,

I've been beating myself up over this one, so any help would be amazing. First, let me give you some background information. I am limited to using the calls fork, pause, kill, malloc, and free. With that in mind, my goal here is to determine what is the maximum number of simultaneous processes that Minix will support for a single user. That said, I need to 1) Fork until I can no longer fork, and pause the process every time I fork so that I can kill it later. 2) Keep track of the pid's in a linked list. Here's my problem, it seems that I can't get nodes into the linked list properly. I really have no clue what to do.

Here's my code:
Code:
#include <sys/types.h>
#include <stdlib.h>
#include <alloca.h>
#include <stdio.h>
#include <unistd.h>

struct pnode {
	int pid;
	struct pnode *next;
};
typedef struct pnode pnode;


int
main(void)
{
	void startKilling(pnode *list);
	void createprocesses(pnode *list, pnode *current, pnode **temp);	
	void getnode(pnode *ptr);
	
	pnode *list;
	pnode *current;
	pnode *temp1;

	int temp;
	
	pid_t pID;	
	pID = 0;
	
	current = list;
	
	createprocesses(list, current, &temp1);
	printf("PID1:  %d\n", list->pid);
	printf("PID2:  %d\n", list->next->pid);

	exit(0);
}

void getnode(pnode *ptr)
{
	ptr = malloc(sizeof(ptr));
	printf("Address of ptr: %d\n", &ptr);
}

void insertnode(pnode *current, pnode *temp, int processid)
{
	pnode temp2;
	getnode(&temp2);
	printf("Current address: %d\n", &current);
	printf("Address: %d\n",&temp2);
	current->pid = processid;
	current->next = &temp2;
	*(&current) = &temp2;
	printf("Current address after reassign: %d\n", &current);
}

void startKilling(pnode *list)
{	
	printf("Merrily killing processes....\n");
	printf("Anything after this should not exist.\n");
}

void createprocesses(pnode *list, pnode *current, pnode **temp) {
	void insertnode(pnode *current, pnode *temp, int processID);
	
	pid_t pID;
	int *counter;

	pID = 0;
	counter = 0;
	
	while(pID != -1) {
		pID = fork();
		if(pID == 0) {
			pause();
			counter = counter + 1;
		} else if(pID < 0) {
			printf("Failed to fork...\n");
		} else {
			/* Parent Process */
			printf("Process ID: %d\n", pID);
			insertnode(current, (*temp), pID);
		}
	}
	printf("Counter: %d\n", counter);
}
As you can tell by looking at my code, I've tried many different methods of doing this, but none of them worked. It seems that whenever I insert a node into the list, it simply overwrites the previous one (in this case, the node pointed to my *list). So basically I never actually insert anything, but simply just keep overwriting *list.

Thanks ahead of time. I'm just not having any luck with it.