Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
How can I kill process Id's from within "Expect"

Posted by pcmenon (pcmenon), 14 May 2005
Hi,

I am running an interactive shell program where I am using expect utility.

I am passing a command in expect ( such as watchqueue" ) that shows all the parsers/daemons running on the IP.

Now the program runs successfully till the display of all parsers/daemons running on my IP.
But I wanna kill this process ( watchqueue) to return to any prompt.

How can I solve this problem,

Please guide me in this regards.

-- pcmenon



Posted by admin (Graham Ellis), 14 May 2005
Your spawn process returns the process id, and you can then use that process id when you exec a kill.   Don't get confused with the spawn_id variable ... that's different, but is also set by the spawn.

Posted by pcmenon (pcmenon), 18 May 2005
Is there any command in expect to kill the spawn returned process ID ?
I tried using normal "kill -9 $PID" but that didn't worked ?

Posted by admin (Graham Ellis), 18 May 2005
exec kill -9 $PID

kill is an operating system dependant command and it's not built in to Tcl or expect.   See Don Libes' book "Exploring Expect" for further examples


Posted by pcmenon (pcmenon), 18 May 2005
Now  I am facing problem as shown below: -
------------------------------------------------------------------
Input:-

set PID "pidof ssh"

exec kill -12 $PID

------------------------------------------------------------------
OUtput:

kill: can't find process "`pidof"
kill: can't find process "ssh'"
   while executing
"exec kill -12 `pidof ssh'"
   (file "./Engine_Parser.exp" line 442)
------------------------------------------------------------------

Posted by admin (Graham Ellis), 18 May 2005
You have to put the process id at the end of the "exec kill" command.   In my example, I assumed that the variable PID contained the process ID; it should NOT contain a string of text in the way you have set it.

I would expect you to spawn your  process something like:

set PID [spawn ........................]

Where you should replace all the dots with the actual details of the process you're starting.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho