[{"data":1,"prerenderedAt":561},["ShallowReactive",2],{"mdc--d6tdd1-key":3,"mdc--btsm6y-key":24,"mdc--lva602-key":126,"mdc-g86z1i-key":156,"mdc--ruj8td-key":287,"mdc--ssiig6-key":299,"mdc-q3xxxz-key":312,"mdc--v9lhaq-key":466,"mdc--vo0ee0-key":546},{"data":4,"body":5},{},{"type":6,"children":7},"root",[8],{"type":9,"tag":10,"props":11,"children":12},"element","p",{},[13,16,22],{"type":14,"value":15},"text","Every running program on a Linux machine is a ",{"type":9,"tag":17,"props":18,"children":19},"strong",{},[20],{"type":14,"value":21},"process",{"type":14,"value":23},", and every process has a number — its PID. Almost all operational work comes down to three questions: what's running, what is it doing, and how do I make it stop.",{"data":25,"body":26},{},{"type":6,"children":27},[28,35,47,59,85,94,99],{"type":9,"tag":29,"props":30,"children":32},"h2",{"id":31},"seeing-whats-running",[33],{"type":14,"value":34},"Seeing what's running",{"type":9,"tag":10,"props":36,"children":37},{},[38,45],{"type":9,"tag":39,"props":40,"children":42},"code",{"className":41},[],[43],{"type":14,"value":44},"ps",{"type":14,"value":46}," lists processes. On its own it shows only yours, in the current terminal, which is rarely what you want. The incantation people actually use is:",{"type":9,"tag":48,"props":49,"children":53},"pre",{"className":50,"code":52,"language":14},[51],"language-text","ps aux\n",[54],{"type":9,"tag":39,"props":55,"children":57},{"__ignoreMap":56},"",[58],{"type":14,"value":52},{"type":9,"tag":10,"props":60,"children":61},{},[62,64,69,71,76,78,83],{"type":14,"value":63},"Which reads as: ",{"type":9,"tag":17,"props":65,"children":66},{},[67],{"type":14,"value":68},"a",{"type":14,"value":70},"ll users' processes, ",{"type":9,"tag":17,"props":72,"children":73},{},[74],{"type":14,"value":75},"u",{"type":14,"value":77},"ser-readable format, including processes with no controlling terminal (",{"type":9,"tag":17,"props":79,"children":80},{},[81],{"type":14,"value":82},"x",{"type":14,"value":84},") — that last one matters because it's how background services show up.",{"type":9,"tag":48,"props":86,"children":89},{"className":87,"code":88,"language":14},[51],"USER   PID  %CPU  %MEM  COMMAND\nroot     1   0.0   0.1  /sbin/init\nyou   2481   0.3   2.1  /usr/bin/node server.js\nyou   3120  98.7   0.4  ./stuck-script.sh\n",[90],{"type":9,"tag":39,"props":91,"children":92},{"__ignoreMap":56},[93],{"type":14,"value":88},{"type":9,"tag":10,"props":95,"children":96},{},[97],{"type":14,"value":98},"PID 1 is always the init system — the first process started at boot, and the ancestor of everything else.",{"type":9,"tag":10,"props":100,"children":101},{},[102,108,110,116,118,124],{"type":9,"tag":39,"props":103,"children":105},{"className":104},[],[106],{"type":14,"value":107},"top",{"type":14,"value":109}," shows the same information but live, sorted by CPU use, refreshing every second or two. ",{"type":9,"tag":39,"props":111,"children":113},{"className":112},[],[114],{"type":14,"value":115},"q",{"type":14,"value":117}," quits it. If ",{"type":9,"tag":39,"props":119,"children":121},{"className":120},[],[122],{"type":14,"value":123},"htop",{"type":14,"value":125}," is installed, it's the nicer version — colour, scrolling, and you can kill processes from inside it.",{"data":127,"body":128},{},{"type":6,"children":129},[130,135],{"type":9,"tag":131,"props":132,"children":134},"terminal-teaser",{":lines":133},"[{\"cmd\":\"ps aux | grep node\",\"out\":\"you   2481  0.3  2.1  /usr/bin/node server.js\"},{\"cmd\":\"kill 2481\"},{\"cmd\":\"ps aux | grep node\",\"out\":\"\"}]",[],{"type":9,"tag":10,"props":136,"children":137},{},[138,140,146,148,154],{"type":14,"value":139},"That first command is a preview of the next lesson — ",{"type":9,"tag":39,"props":141,"children":143},{"className":142},[],[144],{"type":14,"value":145},"ps aux",{"type":14,"value":147}," produced a long list, and ",{"type":9,"tag":39,"props":149,"children":151},{"className":150},[],[152],{"type":14,"value":153},"grep node",{"type":14,"value":155}," kept only the lines mentioning node. Combining two small tools like that is the whole point of the command line.",{"data":157,"body":158},{},{"type":6,"children":159},[160,166,184,193,214,219,228,247],{"type":9,"tag":29,"props":161,"children":163},{"id":162},"stopping-things",[164],{"type":14,"value":165},"Stopping things",{"type":9,"tag":10,"props":167,"children":168},{},[169,175,177,182],{"type":9,"tag":39,"props":170,"children":172},{"className":171},[],[173],{"type":14,"value":174},"kill",{"type":14,"value":176}," sends a ",{"type":9,"tag":17,"props":178,"children":179},{},[180],{"type":14,"value":181},"signal",{"type":14,"value":183}," to a process. Despite the name, it's a general \"send a message\" command, and the default message is a polite one:",{"type":9,"tag":48,"props":185,"children":188},{"className":186,"code":187,"language":14},[51],"kill 2481\n",[189],{"type":9,"tag":39,"props":190,"children":191},{"__ignoreMap":56},[192],{"type":14,"value":187},{"type":9,"tag":10,"props":194,"children":195},{},[196,198,204,206,212],{"type":14,"value":197},"That sends ",{"type":9,"tag":39,"props":199,"children":201},{"className":200},[],[202],{"type":14,"value":203},"SIGTERM",{"type":14,"value":205}," — ",{"type":9,"tag":207,"props":208,"children":209},"em",{},[210],{"type":14,"value":211},"please shut down",{"type":14,"value":213},". A well-behaved program catches it, finishes what it's writing, closes its files, and exits cleanly. This is what you want almost always.",{"type":9,"tag":10,"props":215,"children":216},{},[217],{"type":14,"value":218},"When a process ignores that — genuinely hung, or stuck in a loop that never checks for signals — you escalate:",{"type":9,"tag":48,"props":220,"children":223},{"className":221,"code":222,"language":14},[51],"kill -9 2481\n",[224],{"type":9,"tag":39,"props":225,"children":226},{"__ignoreMap":56},[227],{"type":14,"value":222},{"type":9,"tag":10,"props":229,"children":230},{},[231,237,239,245],{"type":9,"tag":39,"props":232,"children":234},{"className":233},[],[235],{"type":14,"value":236},"-9",{"type":14,"value":238}," is ",{"type":9,"tag":39,"props":240,"children":242},{"className":241},[],[243],{"type":14,"value":244},"SIGKILL",{"type":14,"value":246},", and it's different in kind: the process never sees it. The kernel simply stops scheduling it and reclaims its memory. There's no cleanup, no flushing buffers, no closing files. A database killed this way can leave a corrupted file behind.",{"type":9,"tag":10,"props":248,"children":249},{},[250,252,270,272,277,279,285],{"type":14,"value":251},"So the rule is: ",{"type":9,"tag":17,"props":253,"children":254},{},[255,260,262,268],{"type":9,"tag":39,"props":256,"children":258},{"className":257},[],[259],{"type":14,"value":174},{"type":14,"value":261}," first, ",{"type":9,"tag":39,"props":263,"children":265},{"className":264},[],[266],{"type":14,"value":267},"kill -9",{"type":14,"value":269}," only when it doesn't work.",{"type":14,"value":271}," Reaching for ",{"type":9,"tag":39,"props":273,"children":275},{"className":274},[],[276],{"type":14,"value":236},{"type":14,"value":278}," reflexively is the same mistake as reaching for ",{"type":9,"tag":39,"props":280,"children":282},{"className":281},[],[283],{"type":14,"value":284},"sudo",{"type":14,"value":286}," reflexively.",{"data":288,"body":289},{},{"type":6,"children":290},[291],{"type":9,"tag":292,"props":293,"children":298},"quiz",{":answer":294,":options":295,"explanation":296,"question":297},"0","[\"The process is terminated immediately with no chance to save state or clean up\",\"It requires root permissions that normal users don't have\",\"It kills every process owned by the same user\"]","SIGKILL can't be caught or handled — the kernel just stops the process. Anything half-written stays half-written. Plain `kill` gives the program a chance to exit properly, which is why it's the default.","Why should `kill -9` be a last resort rather than a first move?",[],{"data":300,"body":301},{},{"type":6,"children":302},[303],{"type":9,"tag":304,"props":305,"children":311},"fill-blank",{":answer":306,"explanation":307,"hint":308,"placeholder":309,"prompt":310},"[\"kill 4102\",\"kill -15 4102\",\"kill -TERM 4102\",\"kill -SIGTERM 4102\"]","Plain `kill` sends signal 15 (SIGTERM), so `kill 4102` and `kill -15 4102` are identical.","The plain form of the command is the polite one — no options needed.","kill ...","Send the default termination signal to the process with PID 4102.",[],{"data":313,"body":314},{},{"type":6,"children":315},[316,322,334,354,363,368,418,434,443],{"type":9,"tag":29,"props":317,"children":319},{"id":318},"foreground-background-and-the-two-ctrl-keys",[320],{"type":14,"value":321},"Foreground, background, and the two Ctrl keys",{"type":9,"tag":10,"props":323,"children":324},{},[325,327,332],{"type":14,"value":326},"When you run something, it takes over your terminal — you don't get a prompt back until it finishes. That's the ",{"type":9,"tag":17,"props":328,"children":329},{},[330],{"type":14,"value":331},"foreground",{"type":14,"value":333},".",{"type":9,"tag":10,"props":335,"children":336},{},[337,339,345,347,352],{"type":14,"value":338},"Adding ",{"type":9,"tag":39,"props":340,"children":342},{"className":341},[],[343],{"type":14,"value":344},"&",{"type":14,"value":346}," starts it in the ",{"type":9,"tag":17,"props":348,"children":349},{},[350],{"type":14,"value":351},"background",{"type":14,"value":353}," instead, and hands you the prompt immediately:",{"type":9,"tag":48,"props":355,"children":358},{"className":356,"code":357,"language":14},[51],"./long-running-job.sh &\n",[359],{"type":9,"tag":39,"props":360,"children":361},{"__ignoreMap":56},[362],{"type":14,"value":357},{"type":9,"tag":10,"props":364,"children":365},{},[366],{"type":14,"value":367},"Two keyboard shortcuts control this, and confusing them is common:",{"type":9,"tag":369,"props":370,"children":371},"ul",{},[372,397],{"type":9,"tag":373,"props":374,"children":375},"li",{},[376,382,384,389,390,395],{"type":9,"tag":377,"props":378,"children":379},"kbd",{},[380],{"type":14,"value":381},"Ctrl",{"type":14,"value":383},"+",{"type":9,"tag":377,"props":385,"children":386},{},[387],{"type":14,"value":388},"C",{"type":14,"value":205},{"type":9,"tag":17,"props":391,"children":392},{},[393],{"type":14,"value":394},"stop",{"type":14,"value":396}," the foreground process. This sends SIGINT, asking it to quit.",{"type":9,"tag":373,"props":398,"children":399},{},[400,404,405,410,411,416],{"type":9,"tag":377,"props":401,"children":402},{},[403],{"type":14,"value":381},{"type":14,"value":383},{"type":9,"tag":377,"props":406,"children":407},{},[408],{"type":14,"value":409},"Z",{"type":14,"value":205},{"type":9,"tag":17,"props":412,"children":413},{},[414],{"type":14,"value":415},"suspend",{"type":14,"value":417}," it. The process is paused, not stopped, and is still sitting there consuming memory.",{"type":9,"tag":10,"props":419,"children":420},{},[421,423,427,428,432],{"type":14,"value":422},"After ",{"type":9,"tag":377,"props":424,"children":425},{},[426],{"type":14,"value":381},{"type":14,"value":383},{"type":9,"tag":377,"props":429,"children":430},{},[431],{"type":14,"value":409},{"type":14,"value":433},", three commands manage what you've suspended:",{"type":9,"tag":48,"props":435,"children":438},{"className":436,"code":437,"language":14},[51],"jobs     # list suspended and background jobs in this shell\nfg       # bring the most recent one back to the foreground\nbg       # let it continue, but in the background\n",[439],{"type":9,"tag":39,"props":440,"children":441},{"__ignoreMap":56},[442],{"type":14,"value":437},{"type":9,"tag":10,"props":444,"children":445},{},[446,448,452,453,457,459,464],{"type":14,"value":447},"This is worth knowing because it explains a common confusion: you press ",{"type":9,"tag":377,"props":449,"children":450},{},[451],{"type":14,"value":381},{"type":14,"value":383},{"type":9,"tag":377,"props":454,"children":455},{},[456],{"type":14,"value":409},{"type":14,"value":458}," expecting to quit something, get your prompt back, assume it's gone — and it's still running, or rather still ",{"type":9,"tag":207,"props":460,"children":461},{},[462],{"type":14,"value":463},"paused",{"type":14,"value":465},", until you close the terminal.",{"data":467,"body":468},{},{"type":6,"children":469},[470],{"type":9,"tag":471,"props":472,"children":474},"deep-dive",{"title":473},"Finding a PID when you only know the name",[475,480,489,502,511],{"type":9,"tag":10,"props":476,"children":477},{},[478],{"type":14,"value":479},"You rarely know a PID off the top of your head. Two ways to find one:",{"type":9,"tag":48,"props":481,"children":484},{"className":482,"code":483,"language":14},[51],"pgrep -f \"server.js\"        # print PIDs matching a pattern\nps aux | grep server.js     # the older, more manual version\n",[485],{"type":9,"tag":39,"props":486,"children":487},{"__ignoreMap":56},[488],{"type":14,"value":483},{"type":9,"tag":10,"props":490,"children":491},{},[492,494,500],{"type":14,"value":493},"And you can skip the lookup entirely with ",{"type":9,"tag":39,"props":495,"children":497},{"className":496},[],[498],{"type":14,"value":499},"pkill",{"type":14,"value":501},", which matches by name and signals everything that matches:",{"type":9,"tag":48,"props":503,"children":506},{"className":504,"code":505,"language":14},[51],"pkill -f \"server.js\"\n",[507],{"type":9,"tag":39,"props":508,"children":509},{"__ignoreMap":56},[510],{"type":14,"value":505},{"type":9,"tag":10,"props":512,"children":513},{},[514,516,521,523,529,531,537,539,544],{"type":14,"value":515},"Be careful with ",{"type":9,"tag":39,"props":517,"children":519},{"className":518},[],[520],{"type":14,"value":499},{"type":14,"value":522}," and broad patterns — it will happily match more than you intended. As with ",{"type":9,"tag":39,"props":524,"children":526},{"className":525},[],[527],{"type":14,"value":528},"rm",{"type":14,"value":530},", run the ",{"type":9,"tag":39,"props":532,"children":534},{"className":533},[],[535],{"type":14,"value":536},"pgrep",{"type":14,"value":538}," version first to see the list, ",{"type":9,"tag":207,"props":540,"children":541},{},[542],{"type":14,"value":543},"then",{"type":14,"value":545}," signal it.",{"data":547,"body":548},{},{"type":6,"children":549},[550,556],{"type":9,"tag":292,"props":551,"children":555},{":answer":294,":options":552,"explanation":553,"question":554},"[\"It's suspended — still in memory, paused, and can be resumed with fg\",\"It was terminated cleanly\",\"It moved to the background and is still doing work\"]","Ctrl+Z suspends rather than stops. `jobs` will show it, `fg` resumes it in the foreground, and `bg` lets it carry on in the background. Ctrl+C is the one that actually asks it to quit.","You press Ctrl+Z on a running command and get your prompt back. What happened to the process?",[],{"type":9,"tag":10,"props":557,"children":558},{},[559],{"type":14,"value":560},"Next: the last lesson, and the idea that makes everything so far worth learning.",1787908866327]