{"id":5105,"date":"2019-09-04T10:48:38","date_gmt":"2019-09-04T02:48:38","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=5105"},"modified":"2019-09-04T18:17:18","modified_gmt":"2019-09-04T10:17:18","slug":"%e5%9c%a8-delphi-%e4%b8%ad%e5%88%9b%e5%bb%ba-linux-%e5%ae%88%e6%8a%a4%e7%a8%8b%e5%ba%8f%ef%bc%88%e6%9c%8d%e5%8a%a1%e8%bf%9b%e7%a8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=5105","title":{"rendered":"\u5728 Delphi \u4e2d\u521b\u5efa Linux \u5b88\u62a4\u7a0b\u5e8f\uff08\u670d\u52a1\u8fdb\u7a0b\uff09"},"content":{"rendered":"\n<p>\u672c\u6587\u610f\u8bd1\u81ea <a href=\"https:\/\/chapmanworld.com\/2017\/04\/05\/creating-a-linux-daemon-service-in-delphi\/\">\u539f\u6587\u94fe\u63a5<\/a>\uff0c\u8bed\u8a00\u4e0a\u505a\u4e86\u7cbe\u70bc\u548c\u6392\u7248\u7684\u53d8\u66f4\uff0c\u4ee5\u4fbf\u66f4\u7b80\u6d01\u660e\u4e86\u3002<\/p>\n\n\n\n<p>Delphi \u5f00\u59cb\u652f\u6301 Linux \u5e73\u53f0\u4e3a Delphi \u5f00\u53d1\u4eba\u5458\u5f00\u8f9f\u4e86\u521b\u5efa Linux \u670d\u52a1\u5668\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u80fd\u3002\u4f46\u9057\u61be\u7684\u662f\uff0c\u76ee\u524d RAD Studio IDE \u5e76\u4e0d\u5305\u62ec\u521b\u5efa Linux \u5b88\u62a4\u7a0b\u5e8f\uff08\uff09\u670d\u52a1\uff09\u3002<\/p>\n\n\n\n<p><strong>\u3010\u6ce8\u610f\u3011<\/strong>\u672c\u6587\u5047\u8bbe\u60a8\u5df2\u7ecf\u80fd\u591f\u914d\u7f6e\u597d Linux \u7f16\u8bd1\u73af\u5883\u5e76\u77e5\u9053\u5982\u4f55\u5728 Linux \u547d\u4ee4\u884c\u542f\u52a8\u5b83\u3002\u5426\u5219\u8bf7\u53c2\u8003\uff1a&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/chapmanworld.com\/2017\/02\/28\/embarcadero-delphi-linux-bootcamp\/\">http:\/\/chapmanworld.com\/2017\/02\/28\/embarcadero-delphi-linux-bootcamp\/<\/a><\/li><li><a href=\"http:\/\/chapmanworld.com\/2016\/12\/29\/configure-delphi-and-redhat-or-ubuntu-for-linux-development\/\">http:\/\/chapmanworld.com\/2016\/12\/29\/configure-delphi-and-redhat-or-ubuntu-for-linux-development\/<\/a><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u5b88\u62a4\u8fdb\u7a0b\u3011<\/h4>\n\n\n\n<p>\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0b\uff0c\u5b88\u62a4\u8fdb\u7a0b\u53ea\u662f\u4e00\u4e2a\u6ca1\u6709\u6807\u51c6\u8f93\u5165\u548c\u8f93\u51fa\u6d41\u7684\u8fdb\u7a0b\u3002\u5b83\u5728\u540e\u53f0\u8fd0\u884c\u5e76\u4e0d\u63a5\u53d7\u952e\u76d8\u8f93\u5165\u4e5f\u4e0d\u4f1a\u5411\u5c4f\u5e55\u8f93\u51fa\uff08\u5f53\u7136\u53ef\u4ee5\u8f93\u51fa\u65e5\u5fd7\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u521b\u5efa\u670d\u52a1\u3011<\/h4>\n\n\n\n<p>1\u3001\u521b\u5efa\u4e00\u4e2a\u63a7\u5236\u53f0\u9879\u76ee\uff0c\u5e76\u6dfb\u52a0 Linux64 \u4e3a\u7f16\u8bd1\u76ee\u6807\u3002<br>2\u3001uses \u4e2d\u52a0\u5165 Posix.Unistd \u5355\u5143\uff0c\u4ee5\u4fbf\u5f15\u7528\u5176\u4e2d\u7684 fork \u51fd\u6570\u521b\u5efa\u5b50\u8fdb\u7a0b\u3002<br>3\u3001\u5728\u7a0b\u5e8f\u7684\u5165\u53e3\u5730\u65b9\u52a0\u5165\u5bf9 fork \u7684\u8c03\u7528\uff0c\u4ee5\u521b\u5efa\u5b50\u670d\u52a1\u8fdb\u7a0b\u3002\u6ce8\u610f fork \u51fd\u6570\u7684\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0b ID\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u9700\u8981\u5c06\u5b83\u5199\u5165\u5230\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u63a7\u5236\u670d\u52a1\u7684\u7ed3\u675f\uff08\u8fd9\u662f\u540e\u8bdd\uff0c\u539f\u6587\u4e2d\u6ca1\u8bf4\uff09\uff0c\u4e0b\u9762\u7684\u793a\u4f8b\u53ea\u662f\u505a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u5224\u65ad\u76f4\u63a5\u9000\u51fa\u4e86\u3002<br>4\u3001fork \u6210\u529f\u540e\u8c03\u7528 exit \u9000\u51fa\u5f53\u524d\u8fdb\u7a0b\uff0c\u5982\u679c\u8fd4\u56de\u503c\u4e3a0\uff0c\u4ee3\u8868\u81ea\u5df1\u662f\u5b50\u8fdb\u7a0b\u3002\u7136\u540e\u6267\u884c\u540e\u9762\u7684\u8fdb\u7a0b\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">program Project1;\n{$APPTYPE CONSOLE}\n\n{$R *.res}\n\nuses\n  System.SysUtils,\n  Posix.Unistd;\n\nbegin\n  try\n    if fork()<>0 then begin\n      exit;\n    end;\n    ...\n  except\n    on E: Exception do\n      Writeln(E.ClassName, ': ', E.Message);\n  end;\nend.<\/pre>\n\n\n\n<p>5\u3001\u7f16\u8bd1\u5e76\u53d1\u5e03\u5230\u76ee\u6807\u8ba1\u7b97\u673a\u8fd0\u884c\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u521b\u5efa\u670d\u52a1\u3011<\/h4>\n\n\n\n<p>\u8fd9\u4e00\u6b65\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u4e0d\u592a\u4e00\u6837\uff0c\u65e9\u671f\u7684 Linux \u662f\u521b\u5efa\u4e00\u4e2a\u811a\u672c\uff0c\u653e\u5230 init.d \u91cc\uff0c\u7136\u540e\u4e00\u6b65\u6b65\u6ce8\u518c\u3002\u65b0\u7684 centos \u662f\u5728 \/lib\/systemd\/system \u6dfb\u52a0 xxx.service \u5b9a\u4e49\u3002\u5177\u4f53\u5c31\u53c2\u8003\u76f8\u5e94\u7684\u6587\u6863\u914d\u7f6e\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010QDAC \u7684\u89e3\u51b3\u65b9\u6848\u3011<\/h4>\n\n\n\n<p>qconsole_looper \u4e3a\u60a8\u63d0\u4f9b\u66f4\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5f15\u7528\u8be5\u5355\u5143\uff0c\u7136\u540e\uff1a<\/p>\n\n\n\n<p>TQConsoleLooper.Current.IsDaemon:=True;<br>TQConsoleLooper.Current.PidFile:=&#8221;\u7528\u6765\u5b58\u8d2e\u8fdb\u7a0bPID\u7684\u6587\u4ef6\uff0c\u5982\u679c\u4e0d\u9700\u8981\u4e0d\u7528\u8bbe\u7f6e&#8221;;<br>TQConsoleLooper.Current.Run;<\/p>\n\n\n\n<p>\u5982\u679c\u7a0b\u5e8f\u8981\u54cd\u5e94\u7279\u5b9a\u7684\u4fe1\u53f7\uff0c\u5219\u5728 HandleSignal \u6ce8\u518c\uff0c\u7136\u540e\u54cd\u5e94 OnSignal \u4e8b\u4ef6\u5373\u53ef\u3002\u9ed8\u8ba4\u4f1a\u81ea\u52a8\u54cd\u5e94 SIGQUIT\/SIGABORT\uff0c\u5982\u679c\u7528\u6237\u6ca1\u6709\u81ea\u5df1\u54cd\u5e94\uff0c\u5728\u6536\u5230\u8fd9\u4e24\u4e2a\u4fe1\u53f7\u540e\u4f1a\u81ea\u52a8\u9000\u51fa\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u610f\u8bd1\u81ea \u539f\u6587\u94fe\u63a5\uff0c\u8bed\u8a00\u4e0a\u505a\u4e86\u7cbe\u70bc\u548c\u6392 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8],"tags":[132,773,319],"class_list":["post-5105","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","tag-linux","tag-773","tag-319"],"views":4531,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5105"}],"version-history":[{"count":5,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5105\/revisions"}],"predecessor-version":[{"id":5114,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5105\/revisions\/5114"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}