{"id":2097,"date":"2008-05-09T02:07:35","date_gmt":"2008-05-08T17:07:35","guid":{"rendered":"http:\/\/yasu2.prosou.nu\/blog\/index.php\/2008\/05\/09\/portable_process_killer_with_g\/"},"modified":"2008-05-09T02:07:35","modified_gmt":"2008-05-08T17:07:35","slug":"portable_process_killer_with_g","status":"publish","type":"post","link":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/2008\/05\/09\/2097\/","title":{"rendered":"Portable process killer with GLib"},"content":{"rendered":"<p>Since Windows API (and MinGW) doesn&#8217;t have fork() \/ exec() calls, I love GLib&#8217;s g_spawn_sync() and its friends to spawn child process in portable (and Unix like) way.<br \/>\nHowever, GLib provides nothing like kill() to terminate processes. So I have to find a way to kill a process by myself. As a portable process identifier, g_spawn_sync() gives GPid. This is defined in GLIB_PREFIX\/lib\/glib-2.0\/include\/glibconfig.h as:<br \/>\n&#8211; Unix: typedef int GPid;<br \/>\n&#8211; Win32: typedef void * GPid;<br \/>\nThe one for Unix is equal to pid, and the one for Win32 is equal to HANDLE (defined in winnt.h, as &#8220;typedef void *HANDLE;&#8221;).<br \/>\nSo, a process launched by g_spawn_sync() may be killed by:<br \/>\nkill(GPid p, 15);<br \/>\nTerminateProcess(GPid p, UINT return_code);<br \/>\nMSDN document says &#8220;The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.&#8221;<br \/>\n<a href=\"http:\/\/build.gnome.igalia.com\/gnomebuild\/gimp\/lcov\/app\/plug-in\/gimpplugin.c.gcov.html\">Source code of a Gimp plugin<\/a> gives a good example, but I haven&#8217;t tested it yet. Hope this works&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since Windows API (and MinGW) doesn&#8217;t have fork() \/ exec() calls, I love GLib&#8217;s g_spawn_sync() and &hellip; <a href=\"https:\/\/yasu2.prosou.nu\/blog\/index.php\/2008\/05\/09\/2097\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Portable process killer with GLib&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[9,6],"tags":[32,33,38],"class_list":["post-2097","post","type-post","status-publish","format-standard","hentry","category-mac","category-unix-","tag-cygwinmingw","tag-mac","tag-programming"],"_links":{"self":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2097"}],"version-history":[{"count":0,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2097\/revisions"}],"wp:attachment":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}