I'm a newbie to processes in general and i have this code:
Code:
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>


int main() {
	char buffer[100];
	int pid, status;
	while(1) {
		printf("> ");
		fgets(buffer, sizeof(buffer), stdin);
		printf("here\n");
		switch(pid = fork()) {
			case 0 :
				system(buffer);
		}
		waitpid(pid, &status, 0);
	}
}
( there are too many includes, i know ).

I have to simulate a shell for a university homework and i have the following problem:
Wherever i run this, i read a command from the keyboard and the "here" print always comes AFTER the command's output. Why is this happening? It's very important for my homework.

Stelian