# Sub-processes (like XML.exe, GZIP.exe) not ended properly

I have difficulties with running MathKernel.exe from .NET and sub-processes like XML.exe and GZIP.exe, which are not terminated properly. Sometimes even the MathKernel.exe task stays active and is still blocking a network license.

Basically, the process is: .NET >> call MathKernel.exe, use network license >> Database read+write (XML-stuff and gziped-data) >> terminate MathKernel.exe, release network license.

To give you a minimum working example:

xml:="<abc id=\""<>ToString@RandomInteger[{1, 1000}]<>"\" ManyOtherStuff=\"...\"></abc>";
Table[data[n] = ImportString[xml, "XML"], {n, 1, 20}]


This will generate a list of 20 xml objects. You will notice, that one XML.exe *32 task is started and will stay active (I am running 10.1.0 for Microsoft Windows (64-bit) (March 24, 2015) on a Windows 7 64bit Enterpise, but it's the same on my Windows 2008 R2 server)

The XML stuff is used in the script. Finally, some results are written back to the SQL database as XML and gziped-data.

Table[StringJoin["0x">#]&@(IntegerString[#,16,2]&/@ToCharacterCode@ExportString[data[n],"GZIP"]),{n,1,20}]


This will generate a binary gziped-representation of the data. You will notice, that two GZIP.exe *32 tasks are started and will stay active.

Once you quit the Kernel (MathKernel.exe) or close the frontend (Mathematica.exe), those tasks will disapear.

In my .NET system the MathKernel.exe task is not terminated properly, as the three sub-tasks are still running (I suspect); the MathKernel.exe tasks will still block a license. Sometimes it's running ok (every tasks is terminated properly), but I can't see any reason why. My script is similarly processed all the time.

I would like to understand why the sub-processes are not terminated right away after usage and if I can force them to get closed somehow immediately.

• I do not use .NET/Link, but I'm wondering if the way you are terminating MathKernel.exe is relevant. How do you terminate it specifically? Do you close the MathLink/WSTP link? – Szabolcs Jun 11 '15 at 9:49
• This is the relevant code section: IKernelLink ml = MathLinkFactory.CreateKernelLink(); ml.WaitAndDiscardAnswer(); MathKernel mathKernel = new MathKernel(ml); ... mathKernel.Dispose(); mathKernel = null; ml = null; – akm Jun 11 '15 at 12:05
• Meanwhile, I have tested to eliminate the gzip part by using a gzip-compress method on the sql server (see sqlmag.com/site-files/sqlmag.com/files/archive/sqlmag.com/…). it seems to help, so I suspect the issue with the gzip call via .net – akm Jun 11 '15 at 12:16