ping got possessed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ping got possessed
# 1  
Old 10-04-2012
ping got possessed

Can anyone tell me why my ping got possessed after I ran this command.

Code:
ping google.com & sleep 5 ; kill $!

This is what happened. I hit ctrl+c to end it early. I figured there wouldn't be any problems. Then ping starts back up again and I try to end it again with ctrl+c and it does not work. I finally just open a new tab in my terminal and kill it with the kill command. Why would ctrl+c not work? I thought ctrl+c always works on a foreground process.

Code:
[bob@hi ~]$ ping google.com & sleep 5 ; kill $!
[1] 3095
PING google.com (74.125.229.231) 56(84) bytes of data.
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=1 ttl=55 time=13.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=2 ttl=55 time=18.0 ms
^C
[bob@hi ~]$ 64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=3 ttl=55 time=16.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=4 ttl=55 time=20.2 ms
^C
[bob@hi ~]$ 64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=5 ttl=55 time=15.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=6 ttl=55 time=16.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=7 ttl=55 time=15.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=8 ttl=55 time=17.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=9 ttl=55 time=18.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=10 ttl=55 time=15.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=11 ttl=55 time=16.5 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=13 ttl=55 time=17.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=14 ttl=55 time=13.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=15 ttl=55 time=16.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=16 ttl=55 time=15.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=17 ttl=55 time=16.8 ms
^C
[bob@hi ~]$ 64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=19 ttl=55 time=18.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=20 ttl=55 time=14.7 ms
^C
[bob@hi ~]$ ^C
[bob@hi ~]$ ^C
[bob@hi ~]$ ^C
[bob@hi ~]$ ^C
[bob@hi ~]$ ^C
[bob@hi ~]$ ^C
[bob@hi ~]$ 64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=22 ttl=55 time=15.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=23 ttl=55 time=14.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=24 ttl=55 time=15.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=25 ttl=55 time=16.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=26 ttl=55 time=15.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=27 ttl=55 time=18.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=28 ttl=55 time=21.5 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=29 ttl=55 time=15.4 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=30 ttl=55 time=19.1 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=31 ttl=55 time=20.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=32 ttl=55 time=17.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=33 ttl=55 time=15.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=34 ttl=55 time=144 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=35 ttl=55 time=14.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=36 ttl=55 time=143 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=37 ttl=55 time=16.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=38 ttl=55 time=15.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=40 ttl=55 time=14.6 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=41 ttl=55 time=16.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=42 ttl=55 time=17.1 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=43 ttl=55 time=16.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=44 ttl=55 time=17.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=45 ttl=55 time=16.5 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=46 ttl=55 time=17.4 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=47 ttl=55 time=16.2 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=48 ttl=55 time=14.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=49 ttl=55 time=17.2 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=50 ttl=55 time=15.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=51 ttl=55 time=16.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=52 ttl=55 time=15.1 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=53 ttl=55 time=14.2 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=54 ttl=55 time=17.2 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=55 ttl=55 time=19.7 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=56 ttl=55 time=17.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=57 ttl=55 time=15.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=58 ttl=55 time=17.9 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=59 ttl=55 time=14.8 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=60 ttl=55 time=18.1 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=61 ttl=55 time=17.3 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=62 ttl=55 time=15.4 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=63 ttl=55 time=14.0 ms
64 bytes from mia05s07-in-f7.1e100.net (74.125.229.231): icmp_req=64 ttl=55 time=14.9 ms
^C
[1]+  Killed                  ping google.com
[bob@hi ~]$ 
[bob@hi ~]$ 
[bob@hi ~]$ 
[bob@hi ~]$

# 2  
Old 10-04-2012
In the command line ping google.com & sleep 5 ; kill $!, the & is the command terminator (just like ;). So, first ping google.com is submitted as a background job. Then, the control is passed back to the terminal to execute the line sleep 5 ; kill $!. It seems that you have typed Ctrl-C (after 2 seconds corresponding to the 2 lines of ping output) when this command line was executing so it (the shell) has done what it should do; terminate the foreground process. But, the foreground process was not the ping but the sleep and kill line. So, ping keeps on running in the background, writing periodically to your terminal.

Last edited by elixir_sinari; 10-04-2012 at 04:42 AM..
# 3  
Old 10-04-2012
two proposals to get it to work:
Code:
ping google.com & sleep 5 ; kill %1  #(works in bash with job control)
or
ping google.com & pnr=$!; sleep 5 ; kill $pnr

# 4  
Old 10-04-2012
RudiC, I don't think any of those 2 proposals will work (with INT signal by the user in between). Have you tried these?

Last edited by elixir_sinari; 10-04-2012 at 05:07 AM..
# 5  
Old 10-04-2012
Yes, tested, both work on linux and bash:
Code:
$ ping google.com & pnr=$!; sleep 5 ; kill $pnr
[1] 5233
+ pnr=5233
+ sleep 5
+ ping google.com
PING google.com (173.194.70.102) 56(84) bytes of data.
64 bytes from fa-in-f102.1e100.net (173.194.70.102): icmp_req=1 ttl=50 time=57.5 ms
...
+ kill 5233
$

Code:
$ ping google.com & sleep 5 ; kill %1
[1] 5260
+ sleep 5
+ ping google.com
PING google.com (173.194.70.102) 56(84) bytes of data.
64 bytes from fa-in-f102.1e100.net (173.194.70.102): icmp_req=1 ttl=50 time=59.9 ms
...
+ kill %1
$

I have to admit that it is sensitive to the job no. - if there's more background jobs, %1 won't do.
# 6  
Old 10-04-2012
Even with INT signal (Ctrl-C) by the user after submitting the background job?
# 7  
Old 10-04-2012
Ohhh, got you! You're right, it won't. Tried this, seems better (at least unsusceptible to INT):
Code:
ping google.com & pnr=$!; { sleep 5 ; kill $pnr; } &

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

3. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

4. IP Networking

Can't Ping

I have an old MP-Ras Unix system. I have setup netowkring but am unable to ping any local network pcs or the default gateway. If i use the arp -a command I receive the correct mac address for all connected pcs but I cannot ping anything except the local address. Any help would be appreciative. ... (7 Replies)
Discussion started by: Rutgerncas
7 Replies

5. Solaris

Ping

Hi, I was trying to ping the source and destination i.ps ping -i <source> <destination> <destination> is alive Now i would like to see the packets contiuosly. Please suggest what option can be used with ping command to see For example if i give PING 10.137.58.78: 56 data bytes 64... (3 Replies)
Discussion started by: kkarthik_kaja
3 Replies

6. Linux

Not able to ping

Hi All, Need your help one more time. I am trying to ping a linux machine which is not responding to ping. However traceroute can reach the machine and I can log in to it by ssh. I have checked /proc/sys/net/ipv4/icmp_echo_ignore_all it is already set as "0". It is not happening in the... (1 Reply)
Discussion started by: ailnilanjan
1 Replies

7. UNIX for Dummies Questions & Answers

My unix is possessed!

I'm a n00b. after awhile on the internet my KDE desktop switches windows on it's own. copies weird texts into my termnial window. Generally acts like It's being controlled remotely. I'm using freebsd 6.2 on an intel box. where should I begin to look? (5 Replies)
Discussion started by: script@kiddy
5 Replies

8. UNIX for Dummies Questions & Answers

Ping

Hi , I have one system installed on Linux Red Hat 3.0. I have ip of system 3.156.168.*** and i want to ping some port that is on this IP which command i can do this? sam70 (1 Reply)
Discussion started by: sam70
1 Replies

9. AIX

ping

We can ping out but the return never comes back even to localhost ping localhost PING loopback: (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0 ms it just sits there.... any ideas, any files to check (1 Reply)
Discussion started by: csaunders
1 Replies

10. Shell Programming and Scripting

ping -t

I need a script that recieves an IP adress and a number of seconds as arguments. and display a massage if the IP replies or not. (8 Replies)
Discussion started by: jaber87
8 Replies
Login or Register to Ask a Question