I run this code, actually I want to both processes print the message from "data". But only one does. What happens? Anyone can help?
#include <stdio.h>
main(){
int fd, pid;
char x;
fd = open("data",0); /* open file "data" */
pid = fork();
if(pid != 0){
wait(0);
... (2 Replies)
Hello all.
I'm developing a filetransfer application, which is supposed to work sort of like dcc, with multiple transfers etc. Now i wonder what the best way to manage the transfers is. Should i fork() for each new transfer, hogging loads of memory or use pthreads? Maybe I can use select to see... (0 Replies)
hi all
About this code
for (i = 1; i < n; i++)
if ((childpid = fork()) <= 0)
break;
I really can't understand the output .
and the way fork () return the value .
how about the process Id ,the child process Id and the parent ID
in this case
so please answer me soon (5 Replies)
Hi,
I wrote a simple program for understanding the fork command. The code is as below
int main(void)
{
fork(); printf("hi 1 \n");
fork(); printf("hi 2 \n");
fork(); printf("hi 3 \n");
}
I am getting a variation in the number of times the printf is called if i remove the \n from each of... (1 Reply)
Hi,
I wrote a simple program for understanding the fork command. The code is as below
int main(void)
{
fork(); printf("hi 1 \n");
fork(); printf("hi 2 \n");
fork(); printf("hi 3 \n");
}
I am getting a variation in the number of times the printf is called if i remove the \n from each... (2 Replies)
I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..?
Thanks! (1 Reply)
I understand that fork create a child but I need very simple example that make child useful....
I mean how will make the program faster anyone explain with code plz
using C plz (2 Replies)
Discussion started by: fwrlfo
2 Replies
LEARN ABOUT BSD
fork
FORK(3F)FORK(3F)NAME
fork - create a copy of this process
SYNOPSIS
integer function fork()
DESCRIPTION
Fork creates a copy of the calling process. The only distinction between the 2 processes is that the value returned to one of them
(referred to as the `parent' process) will be the process id of the copy. The copy is usually referred to as the `child' process. The
value returned to the `child' process will be zero.
All logical units open for writing are flushed before the fork to avoid duplication of the contents of I/O buffers in the external file(s).
If the returned value is negative, it indicates an error and will be the negation of the system error code. See perror(3F).
A corresponding exec routine has not been provided because there is no satisfactory way to retain open logical units across the exec. How-
ever, the usual function of fork/exec can be performed using system(3F).
FILES
/usr/lib/libU77.a
SEE ALSO fork(2), wait(3F), kill(3F), system(3F), perror(3F)4.2 Berkeley Distribution May 27, 1986 FORK(3F)