{"id":116,"date":"2026-03-21T22:47:18","date_gmt":"2026-03-21T14:47:18","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-background-process\/"},"modified":"2026-03-21T23:29:00","modified_gmt":"2026-03-21T15:29:00","slug":"gateway-background-process","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-background-process\/","title":{"rendered":"\u540e\u53f0 Exec \u548c Process \u5de5\u5177"},"content":{"rendered":"<h1>\u540e\u53f0 Exec \u548c Process \u5de5\u5177<\/h1>\n<h1>\u540e\u53f0 Exec + Process \u5de5\u5177<\/h1>\n<p>OpenClaw \u901a\u8fc7 <code>exec<\/code> \u5de5\u5177\u8fd0\u884c shell \u547d\u4ee4\uff0c\u5e76\u5c06\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u4efb\u52a1\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u3002<code>process<\/code> \u5de5\u5177\u7ba1\u7406\u8fd9\u4e9b\u540e\u53f0\u4f1a\u8bdd\u3002<\/p>\n<h2>exec \u5de5\u5177<\/h2>\n<p>\u5173\u952e\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><code>command<\/code>\uff08\u5fc5\u586b\uff09<\/li>\n<li><code>yieldMs<\/code>\uff08\u9ed8\u8ba4 10000\uff09\uff1a\u5728\u6b64\u5ef6\u8fdf\u540e\u81ea\u52a8\u8f6c\u4e3a\u540e\u53f0\u8fd0\u884c<\/li>\n<li><code>background<\/code>\uff08\u5e03\u5c14\u503c\uff09\uff1a\u7acb\u5373\u8f6c\u4e3a\u540e\u53f0\u8fd0\u884c<\/li>\n<li><code>timeout<\/code>\uff08\u79d2\uff0c\u9ed8\u8ba4 1800\uff09\uff1a\u5728\u6b64\u8d85\u65f6\u540e\u7ec8\u6b62\u8fdb\u7a0b<\/li>\n<li><code>elevated<\/code>\uff08\u5e03\u5c14\u503c\uff09\uff1a\u5982\u679c\u542f\u7528\/\u5141\u8bb8\u63d0\u6743\u6a21\u5f0f\uff0c\u5219\u5728\u5bbf\u4e3b\u673a\u4e0a\u8fd0\u884c<\/li>\n<li>\u9700\u8981\u771f\u5b9e TTY\uff1f\u8bbe\u7f6e <code>pty: true<\/code>\u3002<\/li>\n<li><code>workdir<\/code>\u3001<code>env<\/code><\/li>\n<\/ul>\n<p>\u884c\u4e3a\uff1a<\/p>\n<ul>\n<li>\u524d\u53f0\u8fd0\u884c\u76f4\u63a5\u8fd4\u56de\u8f93\u51fa\u3002<\/li>\n<li>\u5f53\u8f6c\u4e3a\u540e\u53f0\u8fd0\u884c\uff08\u663e\u5f0f\u6216\u8d85\u65f6\uff09\u65f6\uff0c\u5de5\u5177\u8fd4\u56de <code>status: \"running\"<\/code> + <code>sessionId<\/code> \u548c\u4e00\u5c0f\u6bb5\u5c3e\u90e8\u8f93\u51fa\u3002<\/li>\n<li>\u8f93\u51fa\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u76f4\u5230\u4f1a\u8bdd\u88ab\u8f6e\u8be2\u6216\u6e05\u9664\u3002<\/li>\n<li>\u5982\u679c <code>process<\/code> \u5de5\u5177\u88ab\u7981\u7528\uff0c<code>exec<\/code> \u5c06\u540c\u6b65\u8fd0\u884c\u5e76\u5ffd\u7565 <code>yieldMs<\/code>\/<code>background<\/code>\u3002<\/li>\n<\/ul>\n<h2>\u5b50\u8fdb\u7a0b\u6865\u63a5<\/h2>\n<p>\u5f53\u5728 exec\/process \u5de5\u5177\u4e4b\u5916\u751f\u6210\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u5b50\u8fdb\u7a0b\u65f6\uff08\u4f8b\u5982 CLI \u91cd\u65b0\u751f\u6210\u6216 Gateway \u7f51\u5173 \u7f51\u5173\u8f85\u52a9\u7a0b\u5e8f\uff09\uff0c\u8bf7\u9644\u52a0\u5b50\u8fdb\u7a0b\u6865\u63a5\u8f85\u52a9\u7a0b\u5e8f\uff0c\u4ee5\u4fbf\u7ec8\u6b62\u4fe1\u53f7\u88ab\u8f6c\u53d1\uff0c\u76d1\u542c\u5668\u5728\u9000\u51fa\/\u9519\u8bef\u65f6\u88ab\u5206\u79bb\u3002\u8fd9\u53ef\u4ee5\u907f\u514d\u5728 systemd \u4e0a\u4ea7\u751f\u5b64\u7acb\u8fdb\u7a0b\uff0c\u5e76\u4fdd\u6301\u8de8\u5e73\u53f0\u7684\u5173\u95ed\u884c\u4e3a\u4e00\u81f4\u3002<\/p>\n<p>\u73af\u5883\u53d8\u91cf\u8986\u76d6\uff1a<\/p>\n<ul>\n<li><code>PI_BASH_YIELD_MS<\/code>\uff1a\u9ed8\u8ba4 yield \u65f6\u95f4\uff08\u6beb\u79d2\uff09<\/li>\n<li><code>PI_BASH_MAX_OUTPUT_CHARS<\/code>\uff1a\u5185\u5b58\u8f93\u51fa\u4e0a\u9650\uff08\u5b57\u7b26\uff09<\/li>\n<li><code>OPENCLAW_BASH_PENDING_MAX_OUTPUT_CHARS<\/code>\uff1a\u6bcf\u4e2a\u6d41\u7684\u5f85\u5904\u7406 stdout\/stderr \u4e0a\u9650\uff08\u5b57\u7b26\uff09<\/li>\n<li><code>PI_BASH_JOB_TTL_MS<\/code>\uff1a\u5df2\u5b8c\u6210\u4f1a\u8bdd\u7684 TTL\uff08\u6beb\u79d2\uff0c\u9650\u5236\u5728 1 \u5206\u949f\u81f3 3 \u5c0f\u65f6\u4e4b\u95f4\uff09<\/li>\n<\/ul>\n<p>\u914d\u7f6e\uff08\u63a8\u8350\uff09\uff1a<\/p>\n<ul>\n<li><code>tools.exec.backgroundMs<\/code>\uff08\u9ed8\u8ba4 10000\uff09<\/li>\n<li><code>tools.exec.timeoutSec<\/code>\uff08\u9ed8\u8ba4 1800\uff09<\/li>\n<li><code>tools.exec.cleanupMs<\/code>\uff08\u9ed8\u8ba4 1800000\uff09<\/li>\n<li><code>tools.exec.notifyOnExit<\/code>\uff08\u9ed8\u8ba4 true\uff09\uff1a\u5f53\u540e\u53f0 exec \u9000\u51fa\u65f6\uff0c\u5c06\u7cfb\u7edf\u4e8b\u4ef6\u52a0\u5165\u961f\u5217\u5e76\u8bf7\u6c42\u5fc3\u8df3\u3002<\/li>\n<\/ul>\n<h2>process \u5de5\u5177<\/h2>\n<p>\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li><code>list<\/code>\uff1a\u6b63\u5728\u8fd0\u884c\u548c\u5df2\u5b8c\u6210\u7684\u4f1a\u8bdd<\/li>\n<li><code>poll<\/code>\uff1a\u83b7\u53d6\u4f1a\u8bdd\u7684\u65b0\u8f93\u51fa\uff08\u540c\u65f6\u62a5\u544a\u9000\u51fa\u72b6\u6001\uff09<\/li>\n<li><code>log<\/code>\uff1a\u8bfb\u53d6\u805a\u5408\u8f93\u51fa\uff08\u652f\u6301 <code>offset<\/code> + <code>limit<\/code>\uff09<\/li>\n<li><code>write<\/code>\uff1a\u53d1\u9001 stdin\uff08<code>data<\/code>\uff0c\u53ef\u9009 <code>eof<\/code>\uff09<\/li>\n<li><code>kill<\/code>\uff1a\u7ec8\u6b62\u540e\u53f0\u4f1a\u8bdd<\/li>\n<li><code>clear<\/code>\uff1a\u4ece\u5185\u5b58\u4e2d\u79fb\u9664\u5df2\u5b8c\u6210\u7684\u4f1a\u8bdd<\/li>\n<li><code>remove<\/code>\uff1a\u5982\u679c\u6b63\u5728\u8fd0\u884c\u5219\u7ec8\u6b62\uff0c\u5426\u5219\u6e05\u9664\u5df2\u5b8c\u6210\u7684\u4f1a\u8bdd<\/li>\n<\/ul>\n<p>\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u53ea\u6709\u540e\u53f0\u4f1a\u8bdd\u4f1a\u5728\u5185\u5b58\u4e2d\u5217\u51fa\/\u4fdd\u7559\u3002<\/li>\n<li>\u4f1a\u8bdd\u5728\u8fdb\u7a0b\u91cd\u542f\u65f6\u4f1a\u4e22\u5931\uff08\u65e0\u78c1\u76d8\u6301\u4e45\u5316\uff09\u3002<\/li>\n<li>\u4f1a\u8bdd\u65e5\u5fd7\u53ea\u6709\u5728\u4f60\u8fd0\u884c <code>process poll\/log<\/code> \u4e14\u5de5\u5177\u7ed3\u679c\u88ab\u8bb0\u5f55\u65f6\u624d\u4f1a\u4fdd\u5b58\u5230\u804a\u5929\u5386\u53f2\u3002<\/li>\n<li><code>process<\/code> \u6309\u667a\u80fd\u4f53\u9694\u79bb\uff1b\u5b83\u53ea\u80fd\u770b\u5230\u8be5\u667a\u80fd\u4f53\u542f\u52a8\u7684\u4f1a\u8bdd\u3002<\/li>\n<li><code>process list<\/code> \u5305\u542b\u6d3e\u751f\u7684 <code>name<\/code>\uff08\u547d\u4ee4\u52a8\u8bcd + \u76ee\u6807\uff09\u4ee5\u4fbf\u5feb\u901f\u6d4f\u89c8\u3002<\/li>\n<li><code>process log<\/code> \u4f7f\u7528\u57fa\u4e8e\u884c\u7684 <code>offset<\/code>\/<code>limit<\/code>\uff08\u7701\u7565 <code>offset<\/code> \u4ee5\u83b7\u53d6\u6700\u540e N \u884c\uff09\u3002<\/li>\n<\/ul>\n<h2>\u793a\u4f8b<\/h2>\n<p>\u8fd0\u884c\u957f\u65f6\u95f4\u4efb\u52a1\u5e76\u7a0d\u540e\u8f6e\u8be2\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{ &#8220;tool&#8221;: &#8220;exec&#8221;, &#8220;command&#8221;: &#8220;sleep 5 &amp;&amp; echo done&#8221;, &#8220;yieldMs&#8221;: 1000 }<\/p>\n<pre><code>\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{ &quot;tool&quot;: &quot;process&quot;, &quot;action&quot;: &quot;poll&quot;, &quot;sessionId&quot;: &quot;&lt;id&gt;&quot; }\n<\/code><\/pre>\n<p>\u7acb\u5373\u5728\u540e\u53f0\u542f\u52a8\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{ &#8220;tool&#8221;: &#8220;exec&#8221;, &#8220;command&#8221;: &#8220;npm run build&#8221;, &#8220;background&#8221;: true }<\/p>\n<pre><code>\n\u53d1\u9001 stdin\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{ &quot;tool&quot;: &quot;process&quot;, &quot;action&quot;: &quot;write&quot;, &quot;sessionId&quot;: &quot;&lt;id&gt;&quot;, &quot;data&quot;: &quot;yn&quot; }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u53f0 Exec \u548c Process \u5de5\u5177 \u540e\u53f0 Exec + Process \u5de5\u5177 OpenClaw \u901a\u8fc7 e [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":829,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/829"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}