The second argument to PROCESS: pipe messages is supposed to be a Thread ID.  cuckoomon had been giving it process IDs obtained from thread handles instead in several instances.  Create a new cid_from_thread_handle() to deal with both cases.