LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2002, 09:26 AM   #1
penguinboy
LQ Newbie
 
Registered: Sep 2002
Posts: 2

Rep: Reputation: 0
need help forking pings


i want to make a program that pings a list of ips every 5 mins, and logs the pings

but i need to fork the pings
because if one of the ips goes down it will screw up my log


for example

ping x
ping y
ping z

x time=51.8 ms
y time=did not respond
z time=32.4 ms

well now imagin if i was pinging 50 ips, and 10 of them did not respond, waiting on those 10 would screw up my log unless i could find a way to make it "go around" them but still finish the full ping...

like

ping x
ping y
ping z

x time=51.8 ms
y time=not responding--- forks to ping z
z time=32.4 ms
y time=finishes pinging-did not respond...

i'm sorry if this is confusing.. i'm having a hard time explaining it..

thanks for any help

--bret



Last edited by penguinboy; 09-11-2002 at 09:39 AM.
 
Old 09-11-2002, 10:41 AM   #2
no2nt
Member
 
Registered: Aug 2001
Location: South Carolina, USA
Distribution: Redhat 8.0/Custom
Posts: 96

Rep: Reputation: 16
This sorta does it. You'll have to modify it heavily for your use.

Code:
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>

int main( int argc, char *argv[] )
{
    int a;
    char cmd[256];

    for( a = 1; a < argc; a++ )
    {
	pid_t cpid;
	cpid = fork();

	switch(cpid)
	{
	    case -1: // uh-oh
	    {
		printf("Unable to claim system resources.\n");
		break;
	    }
	    case 0: // i am the child proc
	    {
		char cmd[256];
		
		sprintf(cmd, "ping -c 1 -w 2 %s", argv[a]);
		system(cmd);
		_exit(0); 
		break;
	    }
	    default: // all your child process are belong to us
	    {
		int status;

		//waitpid(cpid, &status, 0);
		break;
	    }
	}
    }

    return 0;
}
And in a scriptable (bash) format:

Code:
#!/bin/bash

IPS="172.26.12.1 172.26.26.2"

for ip in $IPS;
do
    ping -w 2 $ip&
done
Enjoy
 
Old 09-12-2002, 08:10 AM   #3
penguinboy
LQ Newbie
 
Registered: Sep 2002
Posts: 2

Original Poster
Rep: Reputation: 0
hey thanks alot guy, that helped out quite a bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
no pings mrbeeye *BSD 2 05-24-2004 06:49 PM
Pings gbell72 Linux - Networking 2 09-29-2003 09:09 AM
I can't get pings :( dadinou Linux - Networking 4 09-07-2003 04:03 PM
Denying Pings oostevo Linux - Security 6 08-13-2002 09:50 PM
Not responding to pings pilot1 Linux - Newbie 13 06-24-2002 09:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration