[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-ep-29-signal-process-go-javascript-all--*":3,"academy-blog-translations-x9ocrw7fo4szs73":80},{"data":4,"page":79,"perPage":79,"totalItems":79,"totalPages":79},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":73,"keywords":74,"locale":49,"published_at":75,"scheduled_at":13,"school_blog":71,"short_description":76,"slug":77,"status":69,"title":6,"updated":78,"updated_by":13,"views":72},"JS2GO EP.29 Managing Signals and Processes in Go and JavaScript","sclblg987654321","school_blog_translations","\u003Cp>Managing signals and processes is essential for controlling an application’s lifecycle. Whether it’s gracefully stopping a server, restarting processes, or handling background jobs, proper signal and process management ensures stability and reliability. In this article, we compare signal and process handling in Go and JavaScript (Node.js), providing code examples and best practices.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>1. Process and Signal Management in Node.js (JavaScript)\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Node.js provides the \u003Ccode inline=\"\">process\u003C\u002Fcode> and \u003Ccode inline=\"\">child_process\u003C\u002Fcode> modules to handle signals and processes.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Capturing Signals (SIGINT, SIGTERM)\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">process.on('SIGINT', () =&gt; {\n  console.log('Received SIGINT. Exiting gracefully...');\n  process.exit(0);\n});\n\nprocess.on('SIGTERM', () =&gt; {\n  console.log('Received SIGTERM. Cleaning up...');\n  process.exit(0);\n});\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Creating a Child Process\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">const { spawn } = require('child_process');\n\nconst ls = spawn('ls', ['-lh', '\u002Fusr']);\n\nls.stdout.on('data', (data) =&gt; {\n  console.log(`stdout: ${data}`);\n});\n\nls.stderr.on('data', (data) =&gt; {\n  console.error(`stderr: ${data}`);\n});\n\nls.on('close', (code) =&gt; {\n  console.log(`Child process exited with code ${code}`);\n});\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Advantages of Node.js:\u003C\u002Fstrong>\u003Cbr>✔️ Easy to capture signals and control processes\u003Cbr>✔️ Supports asynchronous processes and event-driven patterns\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Limitations:\u003C\u002Fstrong>\u003Cbr>⚠️ Requires event listeners and callbacks\u003Cbr>⚠️ Must be careful of zombie processes when spawning child processes\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>2. Process and Signal Management in Go\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Go uses the \u003Ccode inline=\"\">os\u003C\u002Fcode> and \u003Ccode inline=\"\">os\u002Fsignal\u003C\u002Fcode> packages for process and signal handling.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Capturing Signals (SIGINT, SIGTERM)\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport (\n    \"fmt\"\n    \"os\"\n    \"os\u002Fsignal\"\n    \"syscall\"\n)\n\nfunc main() {\n    sigs := make(chan os.Signal, 1)\n    done := make(chan bool, 1)\n\n    signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)\n\n    go func() {\n        sig := &lt;-sigs\n        fmt.Println()\n        fmt.Println(\"Received signal:\", sig)\n        fmt.Println(\"Cleaning up and exiting...\")\n        done &lt;- true\n    }()\n\n    fmt.Println(\"Waiting for signal...\")\n    &lt;-done\n    fmt.Println(\"Exiting program\")\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Creating a Child Process\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport (\n    \"fmt\"\n    \"os\u002Fexec\"\n)\n\nfunc main() {\n    cmd := exec.Command(\"ls\", \"-lh\", \"\u002Fusr\")\n    output, err := cmd.CombinedOutput()\n    if err != nil {\n        fmt.Println(\"Error:\", err)\n    }\n    fmt.Println(string(output))\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Advantages of Go:\u003C\u002Fstrong>\u003Cbr>✔️ Type-safe and clear error handling\u003Cbr>✔️ Supports signal and process control for backend servers\u003Cbr>✔️ Safely manages the process lifecycle\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Limitations:\u003C\u002Fstrong>\u003Cbr>⚠️ More verbose syntax compared to Node.js\u003Cbr>⚠️ Requires channels and goroutines to handle signals\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>3. Best Practices\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>✔️ Capture signals correctly for graceful shutdown\u003C\u002Fp>\u003Cul>\u003Cli>Node.js: \u003Ccode inline=\"\">process.on('SIGTERM')\u003C\u002Fcode>\u003C\u002Fli>\u003Cli>Go: \u003Ccode inline=\"\">signal.Notify\u003C\u002Fcode> + channel + goroutine\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>✔️ Handle child processes carefully\u003C\u002Fp>\u003Cul>\u003Cli>Use \u003Ccode inline=\"\">stdout\u003C\u002Fcode>\u002F\u003Ccode inline=\"\">stderr\u003C\u002Fcode> to monitor output\u003C\u002Fli>\u003Cli>Wait for the process to finish (\u003Ccode inline=\"\">wait\u003C\u002Fcode> in Go \u002F \u003Ccode inline=\"\">on('close')\u003C\u002Fcode> in Node.js)\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>✔️ Logging and Cleanup\u003C\u002Fp>\u003Cul>\u003Cli>Record events and clean resources (close DB connections, stop server)\u003C\u002Fli>\u003Cli>Prevent zombie processes or memory leaks\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>4. Comparison: Signal &amp; Process Handling JavaScript vs Go\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Feature\u003C\u002Fth>\u003Cth>JavaScript (Node.js)\u003C\u002Fth>\u003Cth>Go\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Capture Signals\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">process.on('SIGINT')\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">signal.Notify\u003C\u002Fcode> + channel\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Child Process\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">child_process.spawn\u003C\u002Fcode> \u002F \u003Ccode inline=\"\">exec\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">os\u002Fexec.Command\u003C\u002Fcode>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Async Handling\u003C\u002Ftd>\u003Ctd>Event-driven \u002F callback\u003C\u002Ftd>\u003Ctd>Goroutine + channel\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Logging\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">console\u003C\u002Fcode> \u002F Winston\u003C\u002Ftd>\u003Ctd>\u003Ccode inline=\"\">fmt\u003C\u002Fcode> \u002F logrus \u002F zap\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Error Handling\u003C\u002Ftd>\u003Ctd>Callback \u002F try\u002Fcatch\u003C\u002Ftd>\u003Ctd>Return error + type-safe\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Graceful Shutdown\u003C\u002Ftd>\u003Ctd>Supported\u003C\u002Ftd>\u003Ctd>Supported\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cstrong>Recommendations:\u003C\u002Fstrong>\u003Cbr>✔️ Web server \u002F event-driven apps → Node.js for rapid development\u003Cbr>✔️ Backend service \u002F concurrent \u002F type-safe → Go for production-critical systems\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Next Episode\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In \u003Cstrong>EP.30\u003C\u002Fstrong>, we will explore \u003Cstrong>Handling HTTP Requests and Responses: JavaScript (Fetch\u002FExpress) vs Go (net\u002Fhttp)\u003C\u002Fstrong> to compare API creation and professional HTTP management.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp data-start=\"498\" data-end=\"834\">\u003Cstrong>Read more\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FGolang\">\u003Cstrong>Golang The Series\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FJS2GO\">\u003Cstrong>JS2GO\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fen\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\">\u003Cstrong>10 Eps That Will Make You a Pro Tailwind CSS Overnight\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🔴 YouTube: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.youtube.com\u002Fchannel\u002FUC2eI2RxcA2zbTqZyHyWIfRg\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevschool\u002F\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdevacademy.com\u002Fen\">\u003Cstrong>https:\u002F\u002Fwww.superdevacademy.com\u002Fen\u003C\u002Fstrong>\u003C\u002Fa>\u003Cstrong>&nbsp;\u003C\u002Fstrong>\u003C\u002Fp>","58_11zon_f0ykwg10h8.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fe2tqtdj80uza8og\u002F58_11zon_f0ykwg10h8.webp","2026-03-04 08:45:59.805Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:45:57.586Z","0k3zwvj92nsa3v0","Signal","2026-04-10 16:13:06.536Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:45:57.801Z","8pb019ksvxqkwgp","Process","2026-04-10 16:13:06.688Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:45:58.078Z","qcza3hvozhvcmtx","child process","2026-04-10 16:13:06.772Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:20:42.484Z","vslzz9nvv6n77cx","JavaScript","2026-04-10 16:07:28.339Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":54,"collectionId":55,"collectionName":56,"expand":57,"id":71,"views":72},"hsa1afr8fcnd6qb","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:24:37.986Z","js2_go_2_11zon_y6paxmuz32.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fhsa1afr8fcnd6qb\u002Fjs2_go_2_11zon_y6paxmuz32.webp",{"en":66,"th":66},"JS2GO",10,"2025-08-11 03:41:08.820Z","published","2026-04-25 02:32:14.339Z","x9ocrw7fo4szs73",206,"e2tqtdj80uza8og",[20,25,30,35,40],"2025-10-15 03:58:24.400Z","Learn how to manage signals and processes in Go and JavaScript with real code examples and best practices to safely and efficiently control your application’s lifecycle.","ep-29-signal-process-go-javascript","2026-04-25 02:47:59.332Z",1,{"en":77}]