Thread: Alarm signal around popen

  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, 10:05 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  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, 02:52 AM