function core_channel_close($req, &$pkt)
{
    global $channel_process_map;
    # XXX remove the closed channel from $readers
    my_print("doing channel close");
    $chan_tlv = packet_get_tlv($req, TLV_TYPE_CHANNEL_ID);
    $id = $chan_tlv['value'];
    $c = get_channel_by_id($id);
    if ($c) {
        # We found a channel, close its stdin/stdout/stderr
        channel_close_handles($id);
        # This is an explicit close from the client, always remove it from the
        # list, even if it has data.
        channel_remove($id);
        # if the channel we're closing is associated with a process, kill the
        # process
        # Make sure the stdapi function for closing a process handle is
        # available before trying to clean up
        if (array_key_exists($id, $channel_process_map) and is_callable('close_process')) {
            close_process($channel_process_map[$id]);
        }
        return ERROR_SUCCESS;
    }
    dump_channels("after close");
    return ERROR_FAILURE;
}
 function stdapi_sys_process_close($req, &$pkt)
 {
     global $processes;
     my_print("doing process_close");
     $handle_tlv = packet_get_tlv($req, TLV_TYPE_PROCESS_HANDLE);
     if (array_key_exists($handle_tlv['value'], $processes)) {
         close_process($processes[$handle_tlv['value']]);
     }
     return ERROR_SUCCESS;
 }