⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-spawning-processes.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EMFILE</code>.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_ERROR_INVAL</code></span></td><td><code class="function"><code class="function">execv()</code></code> returned <code class="literal">EINVAL</code>.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_ERROR_ISDIR</code></span></td><td><code class="function"><code class="function">execv()</code></code> returned <code class="literal">EISDIR</code>.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_ERROR_LIBBAD</code></span></td><td><code class="function"><code class="function">execv()</code></code> returned <code class="literal">ELIBBAD</code>.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_ERROR_FAILED</code></span></td><td>Some other fatal failure, <code class="literal">error-&gt;message</code> should explain.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3044495"></a><h3><a name="G-SPAWN-ERROR:CAPS"></a>G_SPAWN_ERROR</h3><a class="indexterm" name="id3044506"></a><pre class="programlisting">#define G_SPAWN_ERROR g_spawn_error_quark ()</pre><p>Error domain for spawning processes. Errors in this domain willbe from the <a href="glib-Spawning-Processes.html#GSpawnError"><span class="type">GSpawnError</span></a> enumeration. See <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information onerror domains.</p></div><hr><div class="refsect2" lang="en"><a name="id3044539"></a><h3><a name="GSpawnFlags"></a>enum GSpawnFlags</h3><a class="indexterm" name="id3044550"></a><pre class="programlisting">typedef enum{  G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 &lt;&lt; 0,  G_SPAWN_DO_NOT_REAP_CHILD      = 1 &lt;&lt; 1,  /* look for argv[0] in the path i.e. use execvp() */  G_SPAWN_SEARCH_PATH            = 1 &lt;&lt; 2,  /* Dump output to /dev/null */  G_SPAWN_STDOUT_TO_DEV_NULL     = 1 &lt;&lt; 3,  G_SPAWN_STDERR_TO_DEV_NULL     = 1 &lt;&lt; 4,  G_SPAWN_CHILD_INHERITS_STDIN   = 1 &lt;&lt; 5,  G_SPAWN_FILE_AND_ARGV_ZERO     = 1 &lt;&lt; 6} GSpawnFlags;</pre><p>Flags passed to <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a>, <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a> and <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><code class="literal">G_SPAWN_LEAVE_DESCRIPTORS_OPEN</code></span></td><td>the parent's open file descriptors will be  inherited by the child; otherwise all descriptors except stdin/stdout/stderr  will be closed before calling <code class="function"><code class="function">exec()</code></code> in the child.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code></span></td><td>the child will not be automatically reaped; you   must call <code class="function"><code class="function">waitpid()</code></code> or handle <code class="literal">SIGCHLD</code>   yourself, or the child will become a zombie.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_SEARCH_PATH</code></span></td><td><code class="literal">argv[0]</code> need not be an absolute path,   it will be looked for in the user's <code class="envar">PATH</code>.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_STDOUT_TO_DEV_NULL</code></span></td><td>the child's standad output will be discarded,   instead of going to the same location as the parent's standard output.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_STDERR_TO_DEV_NULL</code></span></td><td>the child's standard error will be discarded.</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code></span></td><td>the child will inherit the parent's standard   input (by default, the child's standard input is attached to   <code class="filename">/dev/null</code>).</td></tr><tr><td><span class="term"><code class="literal">G_SPAWN_FILE_AND_ARGV_ZERO</code></span></td><td>the first element of <code class="literal">argv</code> is   the file to execute, while the remaining elements are the actual argument   vector to pass to the file. Normally <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> uses   <code class="literal">argv[0]</code> as the file to execute, and passes all of   <code class="literal">argv</code> to the child.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3044808"></a><h3><a name="GSpawnChildSetupFunc"></a>GSpawnChildSetupFunc ()</h3><a class="indexterm" name="id3044819"></a><pre class="programlisting">void        (*GSpawnChildSetupFunc)         (<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Specifies the type of the setup function passed to <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>,<a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> and <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a>. On POSIX platforms itis called in the child after GLib has performed all the setup it plansto perform but before calling <code class="function"><code class="function">exec()</code></code>. On POSIXactions taken in this function will thus only affect the child, notthe parent.</p><p>On Windows the function is called in the parent. Its usefulness onWindows is thus questionable. In many cases executing the child setupfunction in the parent can have ill effects, and you should be verycareful when porting software to Windows that uses child setupfunctions.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td><td>user data to pass to the function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3044922"></a><h3><a name="g-spawn-async-with-pipes"></a>g_spawn_async_with_pipes ()</h3><a class="indexterm" name="id3044933"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_spawn_async_with_pipes        (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **argv,                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **envp,                                             <a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,                                             <a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,                                             <a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,                                             <a href="glib-Basic-Types.html#gint">gint</a> *standard_input,                                             <a href="glib-Basic-Types.html#gint">gint</a> *standard_output,                                             <a href="glib-Basic-Types.html#gint">gint</a> *standard_error,                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Executes a child program asynchronously (your program will notblock waiting for the child to exit). The child program isspecified by the only argument that must be provided, <em class="parameter"><code>argv</code></em>. <em class="parameter"><code>argv</code></em>should be a <code class="literal">NULL</code>-terminated array of strings, to be passed as theargument vector for the child. The first string in <em class="parameter"><code>argv</code></em> is ofcourse the name of the program to execute. By default, the name ofthe program must be a full path; the <code class="envar">PATH</code> shell variable will only be searched if you pass the <code class="literal">G_SPAWN_SEARCH_PATH</code> flag.</p><p>On Windows, the low-level child process creation API(<code class="function">CreateProcess()</code>)doesn't use argument vectors,but a command line. The C runtime library's<code class="function">spawn*()</code> family of functions (which<a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> eventually calls) paste the argumentvector elements into a command line, and the C runtime startup codedoes a corresponding reconstruction of an argument vector from thecommand line, to be passed to <code class="function">main()</code>. Complications arise when you haveargument vector elements that contain spaces of double quotes. The<code class="function">spawn*()</code> functions don't do any quoting orescaping, but on the other hand the startup code does do unquotingand unescaping in order to enable receiving arguments with embeddedspaces or double quotes. To work around this asymmetry,<a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> will do quoting and escaping on argumentvector elements that need it before calling the C runtime<code class="function">spawn()</code> function.</p><p><em class="parameter"><code>envp</code></em> is a <code class="literal">NULL</code>-terminated array of strings, where each stringhas the form <code class="literal">KEY=VALUE</code>. This will becomethe child's environment. If <em class="parameter"><code>envp</code></em> is <code class="literal">NULL</code>, the child inherits itsparent's environment.</p><p><em class="parameter"><code>flags</code></em> should be the bitwise OR of any flags you want to affect thefunction's behaviour. The <code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code> means that the child will not automatically be reaped; you must use a<span class="type">GChildWatch</span> source to be notified about the death of the child process. Eventually you must call <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> on the<em class="parameter"><code>child_pid</code></em>, in order to free resources which may be associatedwith the child process. (On Unix, using a <span class="type">GChildWatch</span> source isequivalent to calling <code class="function">waitpid()</code> or handling the <code class="literal">SIGCHLD</code> signal manually. On Windows, calling <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> is equivalentto calling <code class="function">CloseHandle()</code> on the process handle returned in <em class="parameter"><code>child_pid</code></em>).</p><p><code class="literal">G_SPAWN_LEAVE_DESCRIPTORS_OPEN</code> means that the parent's open filedescriptors will be inherited by the child; otherwise alldescriptors except stdin/stdout/stderr will be closed beforecalling <code class="function">exec()</code> in the child. <code class="literal">G_SPAWN_SEARCH_PATH</code> means that <code class="literal">argv[0]</code> need not be an absolute path, itwill be looked for in the user's <code class="envar">PATH</code>. <code class="literal">G_SPAWN_STDOUT_TO_DEV_NULL</code> means that the child's standard output will be discarded, instead of going to the same location as the parent's standard output. If you use this flag, <em class="parameter"><code>standard_output</code></em> must be <code class="literal">NULL</code>.<code class="literal">G_SPAWN_STDERR_TO_DEV_NULL</code> means that the child's standard errorwill be discarded, instead of going to the same location as the parent'sstandard error. If you use this flag, <em class="parameter"><code>standard_error</code></em> must be <code class="literal">NULL</code>.<code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code> means that the child will inherit the parent'sstandard input (by default, the child's standard input is attached to/dev/null). If you use this flag, <em class="parameter"><code>standard_input</code></em> must be <code class="literal">NULL</code>.<code class="literal">G_SPAWN_FILE_AND_ARGV_ZERO</code> means that the first element of <em class="parameter"><code>argv</code></em> isthe file to execute, while the remaining elements are the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -