LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-10-2008, 10:04 PM   #1
tqa
LQ Newbie
 
Registered: Jun 2006
Posts: 24

Rep: Reputation: 15
terminate 'ping' without using ctrl-c


hello there!!

Im doing a code for 'ping' command.
can anyone tell me how to terminate the 'ping' process without using the ctrl-c.

I mean is there any way that we can define/fixed the send packet in 'ping'?

anyway, this is my code look like
Code:
#include <iostream>
#include <string>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>

using namespace std;

static string host;
static string ping_2;

void ping()
{
     system("clear");
     cout << "Host: ";
     cin >> host;
     system (("ping " + host).c_str());
     cout << endl;
     cout << "Ping another host? Yes or No: ";
     cin >> ping_2;
     if (ping_2 == "Y" || ping_2 == "y")
     {
     system("clear");
     ping();
     }
     else if (ping_2 == "N" || ping_2 == "n")
     {
     system("exit");
     }
}

int main()
{
     
    ping();
     
     return(0);
}
attention from anyone will really appreciate
Thanks in advance!
 
Old 09-10-2008, 10:27 PM   #2
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 129Reputation: 129
Can't you use the -c [number of packets] option?
 
Old 09-10-2008, 10:50 PM   #3
tqa
LQ Newbie
 
Registered: Jun 2006
Posts: 24

Original Poster
Rep: Reputation: 15
did u mean ping -c[num of packet] at the terminal console?
 
Old 09-10-2008, 11:15 PM   #4
tqa
LQ Newbie
 
Registered: Jun 2006
Posts: 24

Original Poster
Rep: Reputation: 15
ok! i got it!

im using the 'ping -c 4' and it works..
thanks alots!!
 
Old 09-10-2008, 11:47 PM   #5
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: Debian Wheezy
Posts: 2,838

Rep: Reputation: 48
I will apologize in advance, but as much as some people like to complain about an RTFM response, simply checking "man ping" ( SYNOPSIS ping [-dfnqrvR] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] ) would have answered this question.

Perhaps consulting the manual pages would answer the next question too.

No offense to tga in particular.
 
  


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE 3.5.9 - Konqueror - keyboard shortcuts ctrl+, and ctrl+. sometimes stop working bhy Linux - Desktop 1 07-26-2008 11:48 AM
ctrl-c to terminate a process does not work geek1234 Linux - Newbie 1 12-26-2007 02:34 PM
Any way to create bash short cuts (like CTRL+l for clear and Ctrl+D for exit) supersubu123 Linux - General 5 05-30-2007 03:02 AM
ctrl+c & ctrl+v equivalent for Gnome terminal window? halfpower Linux - General 2 11-29-2005 02:57 AM
no ctrl-a or ctrl-z in emacs or on command line? ashlock Fedora 5 12-30-2003 08:00 PM


All times are GMT -5. The time now is 08:47 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration