LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   strange behavior using system() and ping utility (https://www.linuxquestions.org/questions/programming-9/strange-behavior-using-system-and-ping-utility-525132/)

ggeorgak 02-02-2007 10:26 PM

strange behavior using system() and ping utility
 
I am executing system("ping -c 1 -w 1 192.168.1.66"). Supposedly pinging stops either when an ECHO_REPLY has been received or the deadline of 1 second has passed. The strange thing is that the program keeps pinging even though both flags are violated, the scenario is that I have a lan node that gets connected and disconnected from the network. Using Ctrl+C to stop the ping fork process(meaning the system fork process I don't create a new one) I see that it keeps pinging meaning more ECHO_REQUESTS than 1 are sent and the time restriction of 1 second is definitely surpassed.Any ideas of why this is happening?

I forgot to mention that I'm using a SIGALRM handler to call a function that in turn calls system(...). Could this have to do anything with the problem? If yes in what way?

jonwatson 02-03-2007 12:10 AM

I have a similar script that works as expected. I don't have a space between the 'w' and the '1'. Try 'w1'.

ggeorgak 02-04-2007 01:58 AM

I'm pretty sure that the signal handler of SIGALRM has something to do with the problem as using a pthread solved it.

jonwatson 02-04-2007 03:30 AM

Cool. Glad you got it running. How did you solve it?

ggeorgak 02-10-2007 05:55 AM

I just used a pthread instead of a new process and everything worked out fine :)


All times are GMT -5. The time now is 10:22 AM.