Alarm signal around popen

This is a discussion on Alarm signal around popen within the C Programming forums, part of the General Programming Boards category; Hi all, I have an issue with getting a timeout to work with popen. Code: alarm(sig_timeout); read_fp = popen(system_call,"r"); //call ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    Alarm signal around popen

    Hi all,

    I have an issue with getting a timeout to work with popen.

    Code:
    alarm(sig_timeout);
    read_fp = popen(system_call,"r"); //call to a system command
    if (read_fp != NULL)
    {
     chars_read = fread(sys_result, sizeof(char), sizeof(sys_result) - 1, read_fp);	
     pclose(read_fp);
    }
    alarm(0);
    The alarm signal is failing to timeout the popen/fread when the system_call hangs. Have I done something wrong?

    TIA, rotis23

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    additional code if needed:
    Code:
    ....
    
    struct sigaction action;
    int sig_timeout;
    
    ....
    
    bzero(&action, sizeof(action));
    action.sa_handler = timed_out;
    action.sa_flags = 0;
    sigaction(SIGALRM, &action, 0);
    
    sig_timeout = 30;
    
    ....
    
    alarm(sig_timeout);
    read_fp = popen(system_call,"r"); //call to a system command
    if (read_fp != NULL)
    {
     chars_read = fread(sys_result, sizeof(char), sizeof(sys_result) - 1, read_fp);	
     pclose(read_fp);
    }
    alarm(0);

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Is popen() blocking the signal?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    thankyou very much VvV, I shall use select.

    I'll consider my wrist severely slapped for treading the treacherous path of choosing the wrong board. Please forgive me.

    Full marks for noticing my delibarate change for the board of an otherwise perfect variable name.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-07-2009, 11:05 AM
  2. Replies: 3
    Last Post: 10-15-2008, 10:24 AM
  3. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  4. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM
  5. signal handling
    By trekker in forum C Programming
    Replies: 2
    Last Post: 07-05-2002, 03:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21