Witam, otóż muszę zrobić taki program, który będzie wyświetlał nazwy plików z aktualnego folderu. Jeżeli w folderze w którym uruchamiamy program znajdują się inne foldery, to dla nich również należy wyświetlić nazwy znajdujących się w nich plików, lecz to wyświetlanie musi się odbyć w nowym procesie (dziecku?), należy to tworzyć za pomocą forka. Próbowałem to zrobić tak:

 #include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/wait.h>
 
 
int main(int argc, char* argv[]) {

DIR *d;
struct dirent *dir;
struct dirent *dir2;
char tab[50][50];
DIR *proba;

pid_t test;
DIR *testdir;
int i = 0;

d = opendir(".");

char Nazwa[255];



printf("Parent proces ID: %i \n", getppid());

   if (d)
   {
      while((dir = readdir(d)) != NULL)
      {
         printf("Nazwa: %s  Typ: %i \n", dir->d_name, dir->d_type);
         if ((dir->d_type) == 4)
         {
            i = i++;
            strcpy(tab[i], dir->d_name);
            
            
            printf("Nazwa to %s \n", tab[i]);
         }	
      }
   }

closedir(d);
//printf("\n\n omg omg \n");
printf("|| %s || %s || %s ", tab[1], tab[2], tab[3]);

int proces_id;

int g;


for (g = 1; g <= i; g++)
{
//proces_id = fork();
printf("\n\nOtwieramy nowe! \n\n");
/*if (proces_id < 0)
{
	printf("Error");
}
if (proces_id > 0)
{
*/

d = opendir(tab[g]);

if (d)
   {
      while((dir = readdir(d)) != NULL)
      {
         printf("Nazwa: %s  Typ: %i \n", dir->d_name, dir->d_type);
      }
   }

closedir(d);
//wait(NULL);
//}
}

//closedir(d);

}

Jak mam zakomentowane jak teraz, to moim zdaniem działa to poprawnie, ale właśnie nie wiem jak to zrobić przy użyciu forka.