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

  • Home
  • SEARCH
  • 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 6587733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:57:20+00:00 2026-05-25T16:57:20+00:00

I have a program where i ssh into a server and gets data. Here

  • 0

I have a program where i ssh into a server and gets data. Here is the code… I fork it and the child executes the query and the parent waits for the child for a predetermined amount of time (in function timeout) and then kills the child. I did that part because sometimes, i am not exactly sure why, but the ssh connection stops and doesnot exit. That is there is a “ssh -oConnectTimeout=60 blah blah” in the processes list for a long and the timeout function doesnt seem to work. What am i doing wrong here? The last time this problem occured, there was an ssh in process list for 5 days and still it didnot timeout and the program had stopped because it was waiting for the child. There are those extra wait() functions because previously i was getting a lot of defunct processes a.k.a zombies. So i took the easy way out..

c = fork();
if(c==0) {
    close(fd[READ]);

    if (dup2(fd[WRITE],STDOUT_FILENO) != -1)
        execlp("ssh", "ssh -oConnectTimeout=60", serverDetails.c_str(), NULL);
    _exit(1);

}else{
    if(timeout(c) == 1){
        kill(c,SIGTERM);
        waitpid(c, &exitStatus, WNOHANG);
        wait(&exitStatus);
        return 0;
    }
    wait(&exitStatus);
}

This is the timeout function.

int timeout(int childPID)
{
int times = 0, max_times = 10, status, rc;
while (times < max_times){
    sleep(5);
    rc = waitpid(childPID, &status, WNOHANG);
    if(rc < 0){
        perror("waitpid");
        exit(1);
    }
    if(WIFEXITED(status) || WIFSIGNALED(status)){
        /* child exits */
        break;
    }
    times++;
}

if (times >= max_times){
    return 1;
}
else return 0;
}
  • 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-25T16:57:21+00:00Added an answer on May 25, 2026 at 4:57 pm

    SIGTERM just asks for a polite termination of the process. If it’s got stuck, then it won’t respond to that, and you’ll need to use SIGKILL to kill it. Probably after trying SIGTERM and waiting a little while.

    The other possibility is that it’s waiting for the output pipe to the parent process to not be full – maybe there’s enough output to fill the buffer, and the child is waiting on that rather than the network.

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

Sidebar

Related Questions

I have a c++ program that ssh's into a server and runs some commands.
I have a program that logs into a server and issues commands. The results
I have a program that grabs some data through ssh using paramiko: ssh =
Here is the story. I have a Debian 5 server automatically starting into a
In my work with my professor I have to ssh into our server and
I have a program wherein i use fork. In the child process, i just
I have a program that runs osql.exe from microsoft sql server tools directory and
I want to turn a program I have into a service so I can
I have a program that deals with huge amount of data. The process is
I need to be able to ssh from a Java program into a remote

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.