Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:25+00:00 2026-05-22T22:54:25+00:00

I am doing socket programming in C and I want to do the following

  • 0

I am doing socket programming in C and I want to do the following thing:

pid = fork();
if(pid == 0){
    //child process
    for(int m=0;m<2;m++){
        j=0;
        for(i=0;i<len_neighbors;i++){
            socket_des1[i] = get_socket_connection_client(hostname1, neighbor_socket[i],(char *) "udp");
            //sending data to other routers
            cout<<"\nMessage: Sending routing table to neighbor, "<<neighbors[i];
            if (send(socket_des1[i], &message1[0], message1.length(), 0) < 0){
                perror("\nError:Message sending failed\n");
                exit(1);
            }
            j++;
        }
        for(i=0;i<len_neighbors;i++){
            close(socket_des1[i]);
        }
        sleep(30);
        cout<<"Hello";
    }
}else{
    // code for parent process
}

So basically the process will send data to all the neighbors and the goto sleep. What is happening here is the process sends data to first neighbor and then sleeps for 30secs. How do I force the process to finish sending and then execute sleep(30) statement.

I am using forking for the process. And the code above is part of child process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:54:26+00:00Added an answer on May 22, 2026 at 10:54 pm

    I can only guess what is the problem (please add the child code creation to check), I think that when this code is executed by the first child the number of neighbors is 0, with the second the number will be 1, and so on. I would try with a sleep at the beginning so this gives enough time to the others children to fork before sending all the msg.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing some socket programming to transmit information across the wire. I've run
I am currently doing some socket programming using C/C++. To be able to use
`hi I am doing a simple synchronous socket programming,in which i employed twothreads one
I'm doing some fairly simple cross-platform TCP socket programming. I have unfortunately found out
I've been doing socket programming for a while in C++, and kind of got
When we want to pass a descriptor from child to process, UNP V1(Unix network
Linux GCC 4.4.2 I am doing some socket programming. However, I keep getting this
I'm doing some lovely socket programming in objective-C right now and part of my
I'm including the netinet headers and doing some raw socket programming on the iPhone,
I have been doing socket programming for many years, but I have never had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.