Results 1 to 3 of 3
the following code is to ping to a system and c if the connection is established...since pinging has to run as a background process we have to find its pid ...
- 12-01-2007 #1Just Joined!
- Join Date
- Dec 2007
- Location
- bangalore
- Posts
- 38
ping code help neeeded
the following code is to ping to a system and c if the connection is established...since pinging has to run as a background process we have to find its pid and kill it...........
#!/bin/bash
ping 192.168.110.151|cat >f1.c
ps|cat >f2.c
grep ping f1.c|cat f4.c
pid=$(cat<f4.c)
kill -9 $pid
*****************
the problem here is that the pid of the process ping may sometimes be 3 digit or 4 digit or 5 digit so here try to cut the first column assuming it will be a 5 digit the pid is not extracted coz the previous process pid of other processes are 4 or 3 digit...now if i change it to like cut from column 2 after running the script for hundred times it will get a pid of either 3 or 4 digit so the kill command will show error...................somebody who understands this code plz.....help mee..............................reply quick
- 12-01-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Code:pid=$(cat<f4.c| awk '{print $1}')
- 12-04-2007 #3Just Joined!
- Join Date
- Dec 2007
- Location
- bangalore
- Posts
- 38
how to get environment variables in C from a shell script
thanks 4 replying but the above one didnt work
.................................................. ..................................
suppose if i have a shell script which sets an environment variable to a number how do i extract it from a C program???can anyone help me.plzzzzzzzzzzz


Reply With Quote