#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#define BUFF_SIZE 256
#define CHILDS 4
#define DATAFILE "Client_Files.txt"
void worker(int n);
char str_buf[BUFF_SIZE];
FILE *datafile_fp;
int i;
char str_buf[BUFF_SIZE];
pid_t id[CHILDS];
int main() {
if((datafile_fp = fopen( DATAFILE, "r"))== NULL)
printf("grimi");
for ( i = 0; i < CHILDS; i++ ){
id = fork();
if( id == 0 ){
worker(i);
exit(0);
}
else if ( id == -1 ){
printf("fork error.\n");
exit(0);
}
else {
//stuff;
}
}
}
void worker(int n) {
fgets(str_buf, BUFF_SIZE, datafile_fp);
printf("%c",str_buf[0]);
}
how can i share the file descriptor? each child have to read one line.. and they cant read the same one.. this works for the first line.. but then printf doest work...
thanks in advance..