windows - Execution abnormalities depending on process creation (ShellExecute vs CreateProcess) -


we're running windows service responsible monitoring set of processes. service responsible (a) checking if defined jobs running, , (b) starting jobs if not.

the service created via following command (sc: https://technet.microsoft.com/en-us/library/bb490995.aspx):

sc create "my service" binpath= c:\heyoo\myservice.exe type= own start= auto error= normal sc start "scf service" 

one of jobs service responsible creating 'camera.exe'. camera.exe retrieves video feed connected cameras (firewire 1394), , processing on them.

a week ago, service rewritten using shellexecute use createprocess able better monitor defined jobs (as gets handle process).

shellexecute call (old method):

bool execute() {     int result = (int)shellexecute(null, "open", "c:\\bin\\camera.exe", null, null, sw_showdefault);     return result > 32; } 

createprocess call (new method):

// called execute("c:\\bin\\camera.exe", ""); bool execute(std::string prog, std::string args) {     std::string cmd = std::string(prog) + " " + args;     char *path = new char[cmd.length()+1];     strcpy(path, cmd.c_str());      startupinfo si = {0};     si.cb = sizeof(startupinfo);     process_information pi;     zeromemory(&pi, sizeof(pi));      dword creationflags = realtime_priority_class;      bool result = createprocess(null, path, null, null, false, creationflags, null, null, &si, &pi);     delete[] path;      if (result) {         setprocinfo(pi);     }      return result; } 

with new createprocess method, noticed (a) network systematically fails after interval, , (b) images retrieved cameras contain invalid timestamps (correct timestamps crucial us).

a takes down entire network connection, , requires reboot online. b causes processing of images fail, highly dependent on valid timestamps.

the problems (a & b) only arise when service.exe run as service. when running service.exe or camera.exe command line, none of problems occurr.

today removed createprocess calls service (went shellexecute), , problems disappeared again. doing wrong api call?

dword creationflags = realtime_priority_class; 

this obvious difference. when call shellexecute, process created normal priority. documentation real time priority says:

process has highest possible priority. threads of real-time priority class process preempt threads of other processes, including operating system processes performing important tasks. example, real-time process executes more brief interval can cause disk caches not flush or cause mouse unresponsive.

you don't want this!

pass 0 creation flags. documentation says:

if none of priority class flags specified, priority class defaults normal_priority_class unless priority class of creating process idle_priority_class or below_normal_priority_class. in case, child process receives default priority class of calling process.

for worth, can obtain process handle using shellexecuteex rather shellexecute. in fact should prefer shellexecuteex shellexecute since latter cannot report errors properly. so, creating new process, , createprocess right function task.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -