spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to use fork() in c on a file


(I don't really get your code, where is the fork?)

I don't think is a good idea read one file from 2 sibling processes.

From fork(2):

 The child inherits copies of the
parent’s set of open file  descrip-
 tors.   Each  file  descriptor  in the child
refers to the same open
 file description (see open(2)) as the
corresponding file  descriptor
 in  the parent.  This means that the two
descriptors share open file
 status flags, current file offset, and
signal-driven I/O  attributes
 (see the description of F_SETOWN and F_SETSIG in
fcntl(2)).

This means that if you open the file before you fork the process, the processes will share the file descriptors.

If the file descriptors are shared and you want to use several processes to read the file you need to seek the cursor every time a process attempts to read the file. And that call should be protected by a mutex, so probably is not a good solution.


Categories : C

Related to : How to use fork() in c on a file
Recently Add
Rewrite of IDA decompiled function
Computing the average of grades in C
passing structures to functions
Use semaphores for handling sockets in C
How to search for a string pattern inside html, coding in C?
sprintf invalid format '%d'
Why can't this c program run correctly?
Low Pass filter in C
Child process does not print anything
C: datatypes. sqrt function working with int why?
How to implement Serial Port Profile Link Command used in ConnectBlue Bluetooth Module?
Rerunning cancelled pthread
How to print out a string that is pointed to by a char pointer?
Can unverified scanf call cause an undefined behavior?
nested structures in C
Portable Makevars for R package using C, GSL and OpenMP with help of Rcpp
program doesn't run(getting RUN FINISHED Segmentation fault core dumped)
Finding the sign of a Lua number, from C
Width of symbols created by gcc's objectcopy
Strange behavior when using free in c program
Can't open image C
Strange C code - dynamic arrays?
C program printing weird characters
Fault in decimal to binary in c
How to detect broken pipe on input?
How can I ivestigate use of the register keyword in C?
File scaning with fscanf
why gcc generates "leal -8240(%ebp), %eax; cmpl $1, %eax; ja XXX" instead of jmp instruction?
Wierd Problems With My Own Custom Written Word Search Algorithm
Trouble with making a shell in C
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.