Problems with child comunicating with parent on fork()
Hello, I'm trying to implement a version of a bucketSort (kinda) server/client, but I'm having a VERY hard time on making the server behave correctly, when talking to the children, after it forks.
The server is kinda big (300+ lines), so I won't post it here, but here's what I'm doing.
1)create a pipe using
2)all the socket(),bind(),listen() stuff
3)the main loop, now, here's the catch I think
Now, if I start this server and have only one connection, and this connection goes DIRECTLY sending a STOP signal, it works, but, if this connection does something else, or there's another connection (let's say a total of 9 connection for instance), then I have to send 9 diferent STOPs signals to actually kill the server. Where I want just to have to send 1 instead. Also, I want that if the client send some data, that the server acnowledges as being the last data it will ever recieve, to send a done to the main server and continue with all the rest (showing the data it recieved for instance). I thought that by using pipes and read/write on the pipe this would work, but as far as I could see, the read() function is a blocking function, and the main server keeps waiting for something to read, and this could be making some trouble?
I'm really out of ideias here, and really newbie when it comes to fork() and signals processing.
Sorry for the long post, does anyone knows what can possible be wrong? I can post the complete code somewhere over the net if somebody want's to help me.
Also, another question, is there any good way of debuging fork() programs?
It would be nice to see the code from the fork() function onwards. From the posted code it seems that the parent and child process are both reading from the pipe. That is incorrect as the parent should write to the pipe while the child reads from it. Owing to the atomicity of the parent writes it is guaranteed that the child process waits for data to be written to the pipe before pulling it out from its end.
Explain what the code is doing. One basic thing wrong with your code is that you cannot mix local and remote communication calls in the same code. Calls made to pipe() can't be in the same code space as socket() calls.
Hum, I think got a server like it finally right, if you could take a look at the code under EchoServer: Main Page , I think this code is correct tough right? At least it's working perfectly.
It's an ECHO server, simple, that when it receives the string "STOP SERVER\n" it echoes it, and kills the server, gracefully.
If this is correct (I still need to do some code cleaning), I may be rewriting the bucket sort server using this way as a guide line.
Hi everyone
i am very new to linux , working on bash shell.
I am trying to solve the given problem
1. Create a process and then create children using fork
2. Check the Status of the application for successful running.
3. Kill all the process(threads) except parent and first child... (2 Replies)
Hi friends,
I have a small question regarding unix system call fork, I hope you will solve my problem. Here is the small program
$ cat fork1.c
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
int pid;
int x = 0;
x = x + 1;
pid = fork();
if(pid < 0)
{... (2 Replies)
1. The problem statement, all variables and given/known data:
I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process.
2. Relevant commands, code, scripts,... (0 Replies)
i used function fork().
so i made two process.
parent process accepted socket fd and writing to shared memory.
then now. how can child process share parent's socket fd?
is this possible?
Thanks in advance (1 Reply)
Hi all,
I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts.
My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Hi, as I understand fork(), it makes a copy of the parent which becomes a child. But is there anyway to make three children for that one parent. So in other words, if I look up the getppid() of the children, I want them to have the same value??
Thanks in advance to any help! (1 Reply)
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n",... (1 Reply)
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n", getpid(),... (0 Replies)
Hi all, i need to execute a program from within my c++ code. This is no problem. system(), fork(), execxy(). But now i want to able to execute the program as another user as the parent process.
The whole thing is on solaris. I should be possible for both, users with no shell and no password... (1 Reply)
I don't follow what these are...
this is what my text says...
"When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)