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 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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., 2022: 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