xp_cmdshell behavior

  • Hi everybody.

    I got a question about the behavior of xp_cmdshell. Let's pretend that we have the next situation:

    1) There is a stored procedure that uses xp_cmdshell to execute certain .exe (made with VB6, for example) which location is within the server. If we execute this procedure we'll use a "parent SPID".

    2) The .exe makes a connection to the same server, thus uses an SPID different than the SPID that is running xp_cmdshell; this is a "child SPID"

    Let's now pretend that we kill the child SPID. As far as I know, the parent SPID would hang. What would happen if we now kill the parent SPID?.

    In my scenario the parent SPID remains with the famous status of KILLED/ROLLBACK-and-never-ending. And if I try to repeat the process in another window the new parent SPID hangs as well. And then I kill it...and then it remains KILLED/ROLLBACK-and-never-ending and so on.

    Is this the expected behavior of xp_cmdshell? Does it depend on the OS or SQL Server version? Am I missing something?

     

    Regards.

  • All that behaviour depends on the "app" launched by xp_cmdshell. If when you kill the "app" xp_cmdshell receives an exception you don't have to kill the "parent" spid. If it does not then the killed/rollback may or may not finish depending on the status that xp_cmdshell was while you killed the "app".

    These long-term "Killed/Rolled back" spids are not really dangerous but there is no other way to get rid of them than to cycle the service. After SP4 of SQL 2000 these processes are less often observed but it is possible to still happen.

    BTW a VB app on a server is a *bad* idea.

    Cheers,


    * Noel

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply