How to close plugin process?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to close plugin process?

Postby zhengyanadws » Tue May 22, 2018 10:29 pm

I use CEF open a bank website which has a npapi plugin. I find it start an new process, when i close my application this process didn't close.So the app restart.I'm sure the program call the CefShutdown function.

I want to know how to close the process,thank you all.
zhengyanadws
Newbie
 
Posts: 5
Joined: Mon Jan 22, 2018 3:48 am

Re: How to close plugin process?

Postby ndesktop » Wed May 23, 2018 12:48 am

NPAPI plugins are not supported for some time (I assume you are using an older version of CEF).
So, assuming your app is named app.exe, the plugin process should be app.exe --type=plugin (if I remember well).
Normally the plugin subprocess should terminate, but if this is not the case, here is what I've done in the past:
- have a cleanup process (say appcp.exe - CP = cleanup process)
- appcp.exe is launched from app.exe (appcp --pid=app.exe PID) => app.exe PID
- appcp.exe uses the app.exe PID to opens a handle to app.exe (browser, main instance) and waits indefinitely (WaitForSingleObject INFINITE)
- when app.exe closes, the handle is signaled to appcp.exe
- appcp.exe enumerates the processes (CreateToolhelpSnapshot) which (1) have the same path as app.exe and (2) have the parent process PID the one used to launch appcp.exe)
- collects the "orphans" app.exe PIDs, if any
- for each orphan process, appcp.exe
1. (optional) gets the command line if needed (some ntdll things are needed here if you really want to check also if --type=plugin is present in the command line of the orphan process)
this if you need to really validate is a plugin process
2. for each orphan process kill the orphan PID (OpenProcess with TERMINATE and then call TerminateProcess)

I know, is not pleasant, but if for some reason you need this to be done, this is what I've done.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: How to close plugin process?

Postby amaitland » Wed May 23, 2018 2:18 am

You don't need to create a new application for cleanup, you can simply pass the main process Id as a command line arg to your sub processes and spawn a thread that waits for the parent process to exit terminating it's self if required. There are examples on this forum.

Just search this forum for WaitForSingleObject you should find example no problem.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: How to close plugin process?

Postby ndesktop » Wed May 23, 2018 3:11 am

"when i close my application this process didn't close"
On my comment I assumed the browser process is already terminated and still there are pending orphan processes.
And I saw such cases related to NPAPI plugins (simply said, the plugin process was hung because of the plugin, browser terminates but the subprocess still remained in memory doing nothing).
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: How to close plugin process?

Postby zhengyanadws » Wed May 23, 2018 5:07 am

Now I create a new app named "cefSubProcess" and use "settings.browser_subprocess_path".So when i visit the website with plugin, it create a new process "cefSubProcess.exe" instead of my main app.It seems perfect.But if there have three or more "cefSubProcess" process, when I use the close button to close my main app, the main process can not exit.Those sub process can not either.

I have to call the ExitProcess() to exit main process now.I'm sure the cefshutdown has been called.How can i deal with it?
zhengyanadws
Newbie
 
Posts: 5
Joined: Mon Jan 22, 2018 3:48 am

Re: How to close plugin process?

Postby ndesktop » Wed May 23, 2018 5:36 am

It is probably a bug on your app. Do not resort on ExitProcess (or its even more evil twin TerminateProcess) unless you are in crt0exe.c or something.
If you say CefShutdown was called for sure, then is either an unsatisfied wait, a re-a-l-l-y slow debug stacktrace (it happened to me to wait ~20 minutes for a DCHECK backtrace to finish, depending on your settings, symbols loading, AV installed etc), or... a bug.
Unless someone else knowing already what can be will help, attach Visual Studio debugger to all processes in cause, hit Break All, and see who's doing what. Otherwise we're fishing.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: How to close plugin process?

Postby zhengyanadws » Thu May 24, 2018 2:36 am

Now i find a new way to solve it.In OnBeforePluginLoad i remember the browser and all it's plugin path.And in DoClose(),i check the browser and call CefForceWebPluginShutdown() to shutdown all the plugin,it work so perfect.

But if i use the single_process mode,when the app call the CefForceWebPluginShutdown,it start a new app.

I don't know why my app be started.I faced this problem many times.I want to find the reason.
zhengyanadws
Newbie
 
Posts: 5
Joined: Mon Jan 22, 2018 3:48 am

Re: How to close plugin process?

Postby ndesktop » Thu May 24, 2018 3:10 am

Single process mode is not really supported outside quirky debug.
However, if you want to support this, simply do nothing. In single process mode there is no plugin subprocess, everything is inproc.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: How to close plugin process?

Postby zhengyanadws » Thu May 24, 2018 3:21 am

The version i use is 3.2357.1271.And i use cefsetting.single_process = true switch to the single process mode. But when i open a website with npapi plugin,cef create a new process which name is equal with my app's name.I hope the plugin handled in my main process,but it not.Is i do something wrong?
zhengyanadws
Newbie
 
Posts: 5
Joined: Mon Jan 22, 2018 3:48 am

Re: How to close plugin process?

Postby Czarek » Thu May 24, 2018 4:40 am

I don't think plugins are supported in single process mode.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 36 guests