/*
         * We won't like to kill other ss instances' ss_privoxy.exe.
         * This function will check whether the given process is created
         * by this process by checking the module path or command line.
         *
         * Since it's required to put ss in different dirs to run muti instances,
         * different instance will create their unique "privoxy_UID.conf" where
         * UID is hash of ss's location.
         */
        private static bool IsChildProcess(Process process)
        {
            if (Utils.IsPortableMode())
            {
                /*
                 * Under PortableMode, we could identify it by the path of ss_privoxy.exe.
                 */
                try
                {
                    /*
                     * Sometimes Process.GetProcessesByName will return some processes that
                     * are already dead, and that will cause exceptions here.
                     * We could simply ignore those exceptions.
                     */
                    string path = process.MainModule.FileName;
                    return Utils.GetTempPath("ss_privoxy.exe").Equals(path);
                }
                catch (Exception ex)
                {
                    Logging.LogUsefulException(ex);
                    return false;
                }
            }
            else
            {
                try
                {
                    var cmd = process.GetCommandLine();

                    return cmd.Contains(UniqueConfigFile);
                }
                catch (Win32Exception ex)
                {
                    if ((uint) ex.ErrorCode != 0x80004005)
                    {
                        throw;
                    }
                }

                return false;
            }
        }