{"id":41495,"date":"2026-06-04T14:47:12","date_gmt":"2026-06-04T07:47:12","guid":{"rendered":"https:\/\/interdata.vn\/blog\/?p=41495"},"modified":"2026-06-04T14:47:12","modified_gmt":"2026-06-04T07:47:12","slug":"su-dung-lenh-strace-trong-linux","status":"publish","type":"post","link":"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng l\u1ec7nh strace trong Linux t\u1eeb A-Z [2026]"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-white ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed8I DUNG<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Lenh-strace-trong-Linux-la-gi\" >L\u1ec7nh strace trong Linux l\u00e0 g\u00ec?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Cach-cai-dat-strace\" >C\u00e1ch c\u00e0i \u0111\u1eb7t strace<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Tren-Debian-Ubuntu\" >Tr\u00ean Debian \/ Ubuntu<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Tren-CentOS-RHEL\" >Tr\u00ean CentOS \/ RHEL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Tren-Fedora\" >Tr\u00ean Fedora<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Kiem-tra-phien-ban-sau-khi-cai\" >Ki\u1ec3m tra phi\u00ean b\u1ea3n sau khi c\u00e0i<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Huong-dan-giam-sat-va-phan-tich-he-thong-Linux-bang-lenh-strace\" >H\u01b0\u1edbng d\u1eabn gi\u00e1m s\u00e1t v\u00e0 ph\u00e2n t\u00edch h\u1ec7 th\u1ed1ng Linux b\u1eb1ng l\u1ec7nh strace<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#1-Quan-sat-System-Call-Loi-goi-he-thong-tham-so-va-gia-tri-tra-ve\" >1. Quan s\u00e1t System Call (L\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng), tham s\u1ed1 v\u00e0 gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#2-Thong-ke-tong-so-luong-cac-System-Call\" >2. Th\u1ed1ng k\u00ea t\u1ed5ng s\u1ed1 l\u01b0\u1ee3ng c\u00e1c System Call<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#3-Loc-va-chi-theo-doi-mot-System-Call-nhat-dinh\" >3. L\u1ecdc v\u00e0 ch\u1ec9 theo d\u00f5i m\u1ed9t System Call nh\u1ea5t \u0111\u1ecbnh<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#4-Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang-Network\" >4. Gi\u00e1m s\u00e1t c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng thu\u1ed9c nh\u00f3m M\u1ea1ng (Network)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#5-Theo-doi-cac-loi-goi-he-thong-thuoc-nhom-Tin-hieu-Signal\" >5. Theo d\u00f5i c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng thu\u1ed9c nh\u00f3m T\u00edn hi\u1ec7u (Signal)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#6-Hien-thi-dau-thoi-gian-tuong-doi-Relative-Timestamp\" >6. Hi\u1ec3n th\u1ecb d\u1ea5u th\u1eddi gian t\u01b0\u01a1ng \u0111\u1ed1i (Relative Timestamp)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#7-Do-luong-thoi-gian-thuc-thi-cua-tung-System-Call\" >7. \u0110o l\u01b0\u1eddng th\u1eddi gian th\u1ef1c thi c\u1ee7a t\u1eebng System Call<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#8-Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua\" >8. G\u1eafn m\u1ed1c th\u1eddi gian th\u1ef1c (Wall clock time) v\u00e0o k\u1ebft qu\u1ea3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#9-In-gia-tri-cua-con-tro-lenh-Instruction-Pointer-%E2%80%93-IP\" >9. In gi\u00e1 tr\u1ecb c\u1ee7a con tr\u1ecf l\u1ec7nh (Instruction Pointer &#8211; IP)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#10-Xuat-ket-qua-giam-sat-ra-tep-tin\" >10. Xu\u1ea5t k\u1ebft qu\u1ea3 gi\u00e1m s\u00e1t ra t\u1ec7p tin<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Luu-y-khi-dung-strace-tren-production\" >L\u01b0u \u00fd khi d\u00f9ng strace tr\u00ean production<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Cau-hoi-thuong-gap\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#strace-khac-ltrace-o-diem-nao\" >strace kh\u00e1c ltrace \u1edf \u0111i\u1ec3m n\u00e0o?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#Co-the-dung-strace-de-debug-script-Python-hoac-Nodejs-khong\" >C\u00f3 th\u1ec3 d\u00f9ng strace \u0111\u1ec3 debug script Python ho\u1eb7c Node.js kh\u00f4ng?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/interdata.vn\/blog\/su-dung-lenh-strace-trong-linux\/#strace-tra-ve-1-nghia-la-gi\" >strace tr\u1ea3 v\u1ec1 -1 ngh\u0129a l\u00e0 g\u00ec?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<div class=\"summary\">\n<p>\ud83d\udccc<strong> T\u00d3M T\u1eaeT:<\/strong><\/p>\n<p>strace l\u00e0 c\u00f4ng c\u1ee5 d\u00f2ng l\u1ec7nh tr\u00ean <a href=\"https:\/\/interdata.vn\/blog\/he-dieu-hanh-linux-la-gi\/\">Linux<\/a> d\u00f9ng \u0111\u1ec3 ghi l\u1ea1i to\u00e0n b\u1ed9 system call (l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng) v\u00e0 signal m\u00e0 m\u1ed9t ti\u1ebfn tr\u00ecnh th\u1ef1c hi\u1ec7n \u2014 kh\u00f4ng c\u1ea7n <a href=\"https:\/\/interdata.vn\/blog\/source-code-la-gi\/\">source code<\/a>, kh\u00f4ng c\u1ea7n recompile.<\/p>\n<p>B\u00e0i vi\u1ebft n\u00e0y g\u1ed3m:<\/p>\n<ul>\n<li>L\u1ec7nh strace trong Linux l\u00e0 g\u00ec, ho\u1ea1t \u0111\u1ed9ng d\u1ef1a tr\u00ean c\u01a1 ch\u1ebf n\u00e0o<\/li>\n<li>C\u00e1ch c\u00e0i \u0111\u1eb7t tr\u00ean Debian\/Ubuntu, CentOS\/RHEL, <a href=\"https:\/\/interdata.vn\/blog\/fedora-la-gi\/\">Fedora<\/a><\/li>\n<li>C\u00fa ph\u00e1p l\u1ec7nh v\u00e0 b\u1ea3ng t\u00f9y ch\u1ecdn ph\u1ed5 bi\u1ebfn<\/li>\n<li>M\u1ed9t s\u1ed1 l\u01b0u \u00fd khi d\u00f9ng strace tr\u00ean production<\/li>\n<li>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<\/li>\n<\/ul>\n<\/div>\n<p>Ch\u01b0\u01a1ng tr\u00ecnh b\u00e1o l\u1ed7i m\u00e0 kh\u00f4ng c\u00f3 th\u00f4ng b\u00e1o r\u00f5 r\u00e0ng. Ti\u1ebfn tr\u00ecnh ch\u1ea1y nh\u01b0ng c\u1ee9 b\u1ecb treo. File config \u0111\u00fang theo t\u00e0i li\u1ec7u nh\u01b0ng \u1ee9ng d\u1ee5ng v\u1eabn kh\u00f4ng \u0111\u1ecdc \u0111\u01b0\u1ee3c \u2014 nh\u1eefng t\u00ecnh hu\u1ed1ng ki\u1ec3u n\u00e0y x\u1ea3y ra th\u01b0\u1eddng xuy\u00ean h\u01a1n t\u01b0\u1edfng t\u01b0\u1ee3ng khi qu\u1ea3n tr\u1ecb Linux <a href=\"https:\/\/interdata.vn\/blog\/may-chu-server-la-gi\/\">server<\/a>. <strong>strace<\/strong> l\u00e0 c\u00f4ng c\u1ee5 cho ph\u00e9p b\u1ea1n nh\u00ecn th\u1eb3ng v\u00e0o lu\u1ed3ng t\u01b0\u01a1ng t\u00e1c gi\u1eefa ch\u01b0\u01a1ng tr\u00ecnh v\u00e0 kernel \u0111\u1ec3 t\u00ecm ra ch\u00ednh x\u00e1c \u0111i\u1ec1u g\u00ec \u0111ang x\u1ea3y ra.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41518\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Huong-dan-su-dung-lenh-strace-trong-Linux.jpg\" alt=\"H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng l\u1ec7nh strace trong Linux\" width=\"810\" height=\"540\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Huong-dan-su-dung-lenh-strace-trong-Linux.jpg 810w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Huong-dan-su-dung-lenh-strace-trong-Linux-300x200.jpg 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Huong-dan-su-dung-lenh-strace-trong-Linux-768x512.jpg 768w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Lenh-strace-trong-Linux-la-gi\"><\/span>L\u1ec7nh strace trong Linux l\u00e0 g\u00ec?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>strace vi\u1ebft t\u1eaft c\u1ee7a <em>system call tracer<\/em>. C\u00f4ng c\u1ee5 n\u00e0y ho\u1ea1t \u0111\u1ed9ng b\u1eb1ng c\u00e1ch theo d\u00f5i m\u1ecdi l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng m\u00e0 m\u1ed9t ti\u1ebfn tr\u00ecnh th\u1ef1c hi\u1ec7n \u2014 t\u1eeb vi\u1ec7c m\u1edf file, \u0111\u1ecdc\/ghi d\u1eef li\u1ec7u, t\u1ea1o <a href=\"https:\/\/interdata.vn\/blog\/socket-cpu-la-gi\/\">socket<\/a> k\u1ebft n\u1ed1i m\u1ea1ng, cho \u0111\u1ebfn nh\u1eadn t\u00edn hi\u1ec7u t\u1eeb <a href=\"https:\/\/interdata.vn\/blog\/he-dieu-hanh\/\">h\u1ec7 \u0111i\u1ec1u h\u00e0nh<\/a>.<\/p>\n<p>V\u1ec1 m\u1eb7t k\u1ef9 thu\u1eadt, strace d\u1ef1a v\u00e0o c\u01a1 ch\u1ebf <strong>ptrace<\/strong> (process trace) c\u1ee7a Linux kernel. M\u1ed7i khi ti\u1ebfn tr\u00ecnh \u0111\u01b0\u1ee3c theo d\u00f5i th\u1ef1c hi\u1ec7n m\u1ed9t system call, kernel t\u1ea1m d\u1eebng ti\u1ebfn tr\u00ecnh \u0111\u00f3, cho strace ghi l\u1ea1i t\u00ean system call, <a href=\"https:\/\/interdata.vn\/blog\/tham-so-parameter-la-gi\/\">tham s\u1ed1<\/a> truy\u1ec1n v\u00e0o v\u00e0 gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1, sau \u0111\u00f3 m\u1edbi cho ti\u1ebfn tr\u00ecnh ti\u1ebfp t\u1ee5c ch\u1ea1y. \u0110\u00e2y c\u0169ng l\u00e0 l\u00fd do strace g\u00e2y overhead \u2014 tr\u00ean m\u00f4i tr\u01b0\u1eddng production ch\u1ea1y t\u1ea3i cao, b\u1ea1n c\u1ea7n c\u00e2n nh\u1eafc tr\u01b0\u1edbc khi b\u1eadt.<\/p>\n<p>\u0110i\u1ec3m m\u1ea1nh c\u1ee7a strace so v\u1edbi c\u00e1c ph\u01b0\u01a1ng ph\u00e1p <a href=\"https:\/\/interdata.vn\/blog\/wordpress-debug-la-gi\/\">debug<\/a> kh\u00e1c l\u00e0 kh\u00f4ng y\u00eau c\u1ea7u source code. D\u00f9 \u1ee9ng d\u1ee5ng l\u00e0 binary \u0111\u00f3ng, l\u00e0 script kh\u00f4ng c\u00f3 quy\u1ec1n ch\u1ec9nh s\u1eeda, hay th\u1eadm ch\u00ed l\u00e0 ch\u01b0\u01a1ng tr\u00ecnh \u0111ang ch\u1ea1y live \u2014 strace \u0111\u1ec1u quan s\u00e1t \u0111\u01b0\u1ee3c.<\/p>\n<p>Linux cung c\u1ea5p kho\u1ea3ng 200+ system call kh\u00e1c nhau, \u0111\u01b0\u1ee3c li\u1ec7t k\u00ea t\u1ea1i <code>\/usr\/include\/asm\/unistd.h<\/code>. M\u1ed9t s\u1ed1 system call ph\u1ed5 bi\u1ebfn b\u1ea1n s\u1ebd th\u1ea5y th\u01b0\u1eddng xuy\u00ean khi d\u00f9ng strace:<\/p>\n<table>\n<tbody>\n<tr>\n<th>System Call<\/th>\n<th>\u00dd ngh\u0129a<\/th>\n<\/tr>\n<tr>\n<td><code>openat<\/code><\/td>\n<td>M\u1edf file<\/td>\n<\/tr>\n<tr>\n<td><code>read<\/code><\/td>\n<td>\u0110\u1ecdc d\u1eef li\u1ec7u t\u1eeb file descriptor<\/td>\n<\/tr>\n<tr>\n<td><code>write<\/code><\/td>\n<td>Ghi d\u1eef li\u1ec7u v\u00e0o file descriptor<\/td>\n<\/tr>\n<tr>\n<td><code>close<\/code><\/td>\n<td>\u0110\u00f3ng file descriptor<\/td>\n<\/tr>\n<tr>\n<td><code>execve<\/code><\/td>\n<td>Kh\u1edfi ch\u1ea1y ch\u01b0\u01a1ng tr\u00ecnh<\/td>\n<\/tr>\n<tr>\n<td><code>mmap<\/code><\/td>\n<td>\u00c1nh x\u1ea1 v\u00f9ng b\u1ed9 nh\u1edb<\/td>\n<\/tr>\n<tr>\n<td><code>connect<\/code><\/td>\n<td>K\u1ebft n\u1ed1i socket m\u1ea1ng<\/td>\n<\/tr>\n<tr>\n<td><code>getdents64<\/code><\/td>\n<td>\u0110\u1ecdc danh s\u00e1ch file trong th\u01b0 m\u1ee5c<\/td>\n<\/tr>\n<tr>\n<td><code>access<\/code><\/td>\n<td>Ki\u1ec3m tra quy\u1ec1n truy c\u1eadp file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"Cach-cai-dat-strace\"><\/span>C\u00e1ch c\u00e0i \u0111\u1eb7t strace<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Ph\u1ea7n l\u1edbn distro Linux hi\u1ec7n \u0111\u1ea1i \u0111\u00e3 c\u00f3 s\u1eb5n strace trong <a href=\"https:\/\/interdata.vn\/blog\/repository-la-gi\/\">repository<\/a> m\u1eb7c \u0111\u1ecbnh. Ki\u1ec3m tra b\u1eb1ng l\u1ec7nh <code>which strace<\/code> tr\u01b0\u1edbc \u2014 n\u1ebfu tr\u1ea3 v\u1ec1 \u0111\u01b0\u1eddng d\u1eabn th\u00ec \u0111\u00e3 c\u00f3, kh\u00f4ng c\u1ea7n c\u00e0i th\u00eam.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Tren-Debian-Ubuntu\"><\/span>Tr\u00ean Debian \/ Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo apt update\r\nsudo apt install strace<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Tren-CentOS-RHEL\"><\/span>Tr\u00ean CentOS \/ RHEL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo yum install strace<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Tren-Fedora\"><\/span>Tr\u00ean Fedora<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo dnf install strace<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Kiem-tra-phien-ban-sau-khi-cai\"><\/span>Ki\u1ec3m tra phi\u00ean b\u1ea3n sau khi c\u00e0i<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>strace --version<\/code><\/pre>\n<p>Output m\u1eabu:<\/p>\n<pre><code>strace -- version 5.16\r\nCopyright (c) 1991-2022 The strace authors.<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Huong-dan-giam-sat-va-phan-tich-he-thong-Linux-bang-lenh-strace\"><\/span>H\u01b0\u1edbng d\u1eabn gi\u00e1m s\u00e1t v\u00e0 ph\u00e2n t\u00edch h\u1ec7 th\u1ed1ng Linux b\u1eb1ng l\u1ec7nh strace<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>C\u00f4ng c\u1ee5 strace mang \u0111\u1ebfn h\u00e0ng lo\u1ea1t tham s\u1ed1 h\u1eefu \u00edch gi\u00fap b\u1ea1n theo d\u00f5i s\u00e1t sao m\u1ecdi ho\u1ea1t \u0111\u1ed9ng c\u1ee7a c\u00e1c ti\u1ebfn tr\u00ecnh tr\u00ean h\u1ec7 th\u1ed1ng. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 10 ph\u01b0\u01a1ng ph\u00e1p s\u1eed d\u1ee5ng strace ph\u1ed5 bi\u1ebfn nh\u1ea5t d\u00e0nh cho qu\u1ea3n tr\u1ecb vi\u00ean:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1-Quan-sat-System-Call-Loi-goi-he-thong-tham-so-va-gia-tri-tra-ve\"><\/span>1. Quan s\u00e1t System Call (L\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng), tham s\u1ed1 v\u00e0 gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>:\u00a0Trong v\u00ed d\u1ee5 n\u00e0y, ch\u00fang ta d\u00f9ng strace \u0111\u1ec3 gi\u00e1m s\u00e1t ti\u1ebfn tr\u00ecnh ls. Output xu\u1ea5t ra s\u1ebd li\u1ec7t k\u00ea chi ti\u1ebft c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng, \u0111i k\u00e8m c\u00e1c tham s\u1ed1 (n\u1eb1m trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n) v\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a l\u1ec7nh. N\u1ebfu b\u1ea1n th\u1ea5y d\u00f2ng ch\u1eef +++ exited with 0 +++ \u1edf cu\u1ed1i, \u0111i\u1ec1u \u0111\u00f3 c\u00f3 ngh\u0129a l\u00e0 ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 k\u1ebft th\u00fac th\u00e0nh c\u00f4ng. N\u1ebfu c\u00f3 l\u1ed7i x\u1ea3y ra, m\u00e3 tho\u00e1t (exit code) th\u01b0\u1eddng s\u1ebd b\u00e1o l\u00e0 -1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-41519\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Quan-sat-System-Call-1024x581.webp\" alt=\"Quan s\u00e1t System Call\" width=\"1020\" height=\"579\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Quan-sat-System-Call-1024x581.webp 1024w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Quan-sat-System-Call-300x170.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Quan-sat-System-Call-768x436.webp 768w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Quan-sat-System-Call.webp 1263w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"2-Thong-ke-tong-so-luong-cac-System-Call\"><\/span>2. Th\u1ed1ng k\u00ea t\u1ed5ng s\u1ed1 l\u01b0\u1ee3ng c\u00e1c System Call<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -c ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: L\u1ec7nh ls l\u00e0 l\u1ec7nh c\u1ea7n theo d\u00f5i. Tham s\u1ed1 -c gi\u00fap b\u1ea1n t\u1ea1o ra m\u1ed9t b\u1ea3ng b\u00e1o c\u00e1o t\u1ed5ng h\u1ee3p. Thay v\u00ec in ra to\u00e0n b\u1ed9 qu\u00e1 tr\u00ecnh, n\u00f3 s\u1ebd hi\u1ec3n th\u1ecb m\u1ed7i l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c thi bao nhi\u00eau l\u1ea7n, t\u1ed5ng s\u1ed1 l\u01b0\u1ee3ng g\u1ecdi v\u00e0 th\u1eddi gian ti\u00eau t\u1ed1n cho m\u1ed7i thao t\u00e1c \u0111\u00f3.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-41520\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Thong-ke-tong-so-luong-cac-System-Call-1024x513.webp\" alt=\"Th\u1ed1ng k\u00ea t\u1ed5ng s\u1ed1 l\u01b0\u1ee3ng c\u00e1c System Call\" width=\"1020\" height=\"511\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Thong-ke-tong-so-luong-cac-System-Call-1024x513.webp 1024w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Thong-ke-tong-so-luong-cac-System-Call-300x150.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Thong-ke-tong-so-luong-cac-System-Call-768x385.webp 768w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Thong-ke-tong-so-luong-cac-System-Call.webp 1052w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"3-Loc-va-chi-theo-doi-mot-System-Call-nhat-dinh\"><\/span>3. L\u1ecdc v\u00e0 ch\u1ec9 theo d\u00f5i m\u1ed9t System Call nh\u1ea5t \u0111\u1ecbnh<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -e trace=write ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: Khi b\u1ea1n ch\u1ec9 mu\u1ed1n t\u1eadp trung v\u00e0o m\u1ed9t h\u00e0nh \u0111\u1ed9ng c\u1ee5 th\u1ec3 (v\u00ed d\u1ee5: l\u1ec7nh ghi d\u1eef li\u1ec7u write), c\u00fa ph\u00e1p n\u00e0y s\u1ebd lo\u1ea1i b\u1ecf c\u00e1c th\u00f4ng tin th\u1eeba. K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 s\u1ebd ch\u1ec9 hi\u1ec3n th\u1ecb t\u00ean, tham s\u1ed1 v\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a duy nh\u1ea5t l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng write.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4-Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang-Network\"><\/span>4. Gi\u00e1m s\u00e1t c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng thu\u1ed9c nh\u00f3m M\u1ea1ng (Network)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -e trace=network nc -v -n 127.0.0.1 801<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: \u1ede \u0111\u00e2y, ti\u1ebfn tr\u00ecnh m\u1ee5c ti\u00eau l\u00e0 nc -v -n 127.0.0.1 801. Khi th\u00eam t\u00f9y ch\u1ecdn trace=network, h\u1ec7 th\u1ed1ng s\u1ebd t\u1ef1 \u0111\u1ed9ng l\u1ecdc v\u00e0 ch\u1ec9 in ra m\u00e0n h\u00ecnh c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng c\u00f3 li\u00ean quan tr\u1ef1c ti\u1ebfp \u0111\u1ebfn c\u00e1c ho\u1ea1t \u0111\u1ed9ng giao ti\u1ebfp m\u1ea1ng.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41521\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang.webp\" alt=\"Gi\u00e1m s\u00e1t c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng thu\u1ed9c nh\u00f3m M\u1ea1ng\" width=\"880\" height=\"203\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang.webp 880w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang-300x69.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Giam-sat-cac-loi-goi-he-thong-thuoc-nhom-Mang-768x177.webp 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"5-Theo-doi-cac-loi-goi-he-thong-thuoc-nhom-Tin-hieu-Signal\"><\/span>5. Theo d\u00f5i c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng thu\u1ed9c nh\u00f3m T\u00edn hi\u1ec7u (Signal)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -e trace=signal nc -v -n 127.0.0.1 801<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: T\u01b0\u01a1ng t\u1ef1 nh\u01b0 v\u00ed d\u1ee5 tr\u00ean, nh\u01b0ng v\u1edbi t\u1eeb kh\u00f3a trace=signal, c\u00f4ng c\u1ee5 s\u1ebd t\u00e1ch bi\u1ec7t v\u00e0 ch\u1ec9 hi\u1ec3n th\u1ecb c\u00e1c l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng ch\u1ecbu tr\u00e1ch nhi\u1ec7m x\u1eed l\u00fd c\u00e1c t\u00edn hi\u1ec7u (signal) c\u1ee7a ti\u1ebfn tr\u00ecnh.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6-Hien-thi-dau-thoi-gian-tuong-doi-Relative-Timestamp\"><\/span>6. Hi\u1ec3n th\u1ecb d\u1ea5u th\u1eddi gian t\u01b0\u01a1ng \u0111\u1ed1i (Relative Timestamp)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -r ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: L\u1ec7nh ls l\u00e0 l\u1ec7nh c\u1ea7n theo d\u00f5i. T\u00f9y ch\u1ecdn -r s\u1ebd ch\u00e8n th\u00eam m\u1ed9t m\u1ed1c th\u1eddi gian t\u01b0\u01a1ng \u0111\u1ed1i t\u00ednh t\u1eeb l\u00fac l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng b\u1eaft \u0111\u1ea7u. Ch\u1ec9 s\u1ed1 n\u00e0y \u0111\u1eb7c bi\u1ec7t h\u1eefu \u00edch khi b\u1ea1n mu\u1ed1n ph\u00e2n t\u00edch kho\u1ea3ng th\u1eddi gian tr\u1ec5 (delay) gi\u1eefa hai l\u1eddi g\u1ecdi x\u1ea3y ra li\u00ean ti\u1ebfp.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-41522\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Hien-thi-dau-thoi-gian-tuong-doi-1024x258.webp\" alt=\"Hi\u1ec3n th\u1ecb d\u1ea5u th\u1eddi gian t\u01b0\u01a1ng \u0111\u1ed1i\" width=\"1020\" height=\"257\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Hien-thi-dau-thoi-gian-tuong-doi-1024x258.webp 1024w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Hien-thi-dau-thoi-gian-tuong-doi-300x76.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Hien-thi-dau-thoi-gian-tuong-doi-768x193.webp 768w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Hien-thi-dau-thoi-gian-tuong-doi.webp 1335w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"7-Do-luong-thoi-gian-thuc-thi-cua-tung-System-Call\"><\/span>7. \u0110o l\u01b0\u1eddng th\u1eddi gian th\u1ef1c thi c\u1ee7a t\u1eebng System Call<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -T ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: L\u1ec7nh ls l\u00e0 l\u1ec7nh c\u1ea7n theo d\u00f5i. \u0110\u1ec3 bi\u1ebft m\u1ed9t l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng ti\u00eau t\u1ed1n h\u1ebft bao nhi\u00eau th\u1eddi gian x\u1eed l\u00fd, h\u00e3y d\u00f9ng c\u1edd -T. Th\u00f4ng s\u1ed1 th\u1eddi gian th\u1ef1c thi n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c \u0111\u00ednh k\u00e8m \u1edf ngay cu\u1ed1i m\u1ed7i d\u00f2ng k\u1ebft qu\u1ea3.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8-Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua\"><\/span>8. G\u1eafn m\u1ed1c th\u1eddi gian th\u1ef1c (Wall clock time) v\u00e0o k\u1ebft qu\u1ea3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -t ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: L\u1ec7nh ls l\u00e0 l\u1ec7nh c\u1ea7n theo d\u00f5i. C\u00fa ph\u00e1p n\u00e0y gi\u00fap b\u1ea1n \u0111\u1ed1i chi\u1ebfu th\u1eddi gian d\u1ec5 d\u00e0ng h\u01a1n b\u1eb1ng c\u00e1ch th\u00eam tr\u1ef1c ti\u1ebfp gi\u1edd h\u1ec7 th\u1ed1ng (theo m\u1ed1c th\u1eddi gian th\u1ef1c) v\u00e0o \u0111\u1ea7u m\u1ed7i d\u00f2ng hi\u1ec3n th\u1ecb l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-41523\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua-1024x287.webp\" alt=\"G\u1eafn m\u1ed1c th\u1eddi gian th\u1ef1c (Wall clock time) v\u00e0o k\u1ebft qu\u1ea3\" width=\"1020\" height=\"286\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua-1024x287.webp 1024w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua-300x84.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua-768x215.webp 768w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/Gan-moc-thoi-gian-thuc-Wall-clock-time-vao-ket-qua.webp 1236w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"9-In-gia-tri-cua-con-tro-lenh-Instruction-Pointer-%E2%80%93-IP\"><\/span>9. In gi\u00e1 tr\u1ecb c\u1ee7a con tr\u1ecf l\u1ec7nh (Instruction Pointer &#8211; IP)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -i ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: L\u1ec7nh ls l\u00e0 l\u1ec7nh c\u1ea7n theo d\u00f5i. D\u00e0nh cho nh\u1eefng ai c\u1ea7n debug s\u00e2u h\u01a1n \u1edf m\u1ee9c ph\u1ea7n c\u1ee9ng\/b\u1ed9 nh\u1edb, t\u00f9y ch\u1ecdn -i s\u1ebd b\u1ed5 sung th\u00eam gi\u00e1 tr\u1ecb c\u1ee7a thanh ghi con tr\u1ecf l\u1ec7nh (<a href=\"https:\/\/interdata.vn\/blog\/dia-chi-ip-la-gi\/\">IP<\/a>) v\u00e0o m\u1ed7i d\u00f2ng output.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-41524\" src=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/In-gia-tri-cua-con-tro-lenh-1024x272.webp\" alt=\"In gi\u00e1 tr\u1ecb c\u1ee7a con tr\u1ecf l\u1ec7nh\" width=\"1020\" height=\"271\" title=\"\" srcset=\"https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/In-gia-tri-cua-con-tro-lenh-1024x272.webp 1024w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/In-gia-tri-cua-con-tro-lenh-300x80.webp 300w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/In-gia-tri-cua-con-tro-lenh-768x204.webp 768w, https:\/\/interdata.vn\/blog\/wp-content\/uploads\/2026\/06\/In-gia-tri-cua-con-tro-lenh.webp 1368w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"10-Xuat-ket-qua-giam-sat-ra-tep-tin\"><\/span>10. Xu\u1ea5t k\u1ebft qu\u1ea3 gi\u00e1m s\u00e1t ra t\u1ec7p tin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>strace -o output.txt ls<\/code><\/p>\n<p><strong>Gi\u1ea3i th\u00edch<\/strong>: Thay v\u00ec in m\u1ed9t danh s\u00e1ch k\u1ebft qu\u1ea3 d\u00e0i ngo\u1eb1ng ra m\u00e0n h\u00ecnh terminal, tham s\u1ed1 -o s\u1ebd \u0111i\u1ec1u h\u01b0\u1edbng to\u00e0n b\u1ed9 d\u1eef li\u1ec7u theo d\u00f5i \u0111\u01b0\u1ee3c v\u00e0 l\u01b0u g\u1ecdn g\u00e0ng v\u00e0o t\u1ec7p v\u0103n b\u1ea3n c\u00f3 t\u00ean output.txt \u0111\u1ec3 b\u1ea1n ti\u1ec7n xem l\u1ea1i sau.<\/p>\n<div class=\"cta-box\">\n<p><span style=\"color: #ed1c24; font-size: 130%;\"><strong>C\u1ea7n thu\u00ea <a href=\"https:\/\/interdata.vn\/blog\/vps-la-gi\/\">VPS<\/a> Linux c\u1ea7n cho c\u00f4ng vi\u1ec7c debug v\u00e0 qu\u1ea3n tr\u1ecb h\u1ec7 th\u1ed1ng?<\/strong><\/span><\/p>\n<p>InterData cung c\u1ea5p d\u1ecbch v\u1ee5 VPS t\u1ed1c \u0111\u1ed9 cao v\u1edbi full <a href=\"https:\/\/interdata.vn\/blog\/root-access-la-gi\/\">root access<\/a>, ph\u1ea7n c\u1ee9ng th\u1ebf h\u1ec7 m\u1edbi, SSD NVMe t\u1ed1c \u0111\u1ed9 cao, h\u1ed7 tr\u1ee3 \u0111a d\u1ea1ng h\u1ec7 \u0111i\u1ec1u h\u00e0nh \u2014 ph\u00f9 h\u1ee3p t\u1eeb developer c\u00e1 nh\u00e2n \u0111\u1ebfn h\u1ec7 th\u1ed1ng doanh nghi\u1ec7p.<\/p>\n<a href=\"https:\/\/interdata.vn\/thue-vps\/\" class=\"button primary is-primary is-medium\"  >\n\t\t<span>THAM KH\u1ea2O B\u1ea2NG GI\u00c1 VPS HI\u1ec6U N\u0102NG CAO<\/span>\n\t<\/a>\n\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Luu-y-khi-dung-strace-tren-production\"><\/span>L\u01b0u \u00fd khi d\u00f9ng strace tr\u00ean production<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>strace l\u00e0m ch\u1eadm ti\u1ebfn tr\u00ecnh \u0111\u01b0\u1ee3c trace \u0111\u00e1ng k\u1ec3 v\u00ec m\u1ed7i system call \u0111\u1ec1u b\u1ecb kernel d\u1eebng l\u1ea1i \u0111\u1ec3 ghi nh\u1eadn. M\u1ee9c overhead th\u1ef1c t\u1ebf ph\u1ee5 thu\u1ed9c v\u00e0o s\u1ed1 l\u01b0\u1ee3ng system call per gi\u00e2y \u2014 v\u1edbi c\u00e1c ch\u01b0\u01a1ng tr\u00ecnh I\/O-heavy c\u00f3 th\u1ec3 ch\u1eadm \u0111\u1ebfn 10-20 l\u1ea7n.<\/p>\n<p>M\u1ed9t s\u1ed1 \u0111i\u1ec3m c\u1ea7n nh\u1edb:<\/p>\n<ul>\n<li>Ch\u1ec9 trace trong th\u1eddi gian ng\u1eafn khi \u0111i\u1ec1u tra s\u1ef1 c\u1ed1, kh\u00f4ng \u0111\u1ec3 ch\u1ea1y li\u00ean t\u1ee5c<\/li>\n<li>D\u00f9ng <code>-e trace=<\/code> \u0111\u1ec3 l\u1ecdc ch\u1ec9 nh\u00f3m system call c\u1ea7n thi\u1ebft, gi\u1ea3m overhead<\/li>\n<li>\u1ee8ng d\u1ee5ng c\u00f3 th\u1ec3 t\u1ef1 kh\u00f3a kh\u00f4ng cho ptrace b\u1eb1ng syscall <code>prctl<\/code> \u2014 trong tr\u01b0\u1eddng h\u1ee3p \u0111\u00f3 strace s\u1ebd kh\u00f4ng attach \u0111\u01b0\u1ee3c d\u00f9 c\u00f3 root<\/li>\n<li>Tr\u00ean container <a href=\"https:\/\/interdata.vn\/blog\/docker-la-gi\/\">Docker<\/a> ho\u1eb7c m\u00f4i tr\u01b0\u1eddng sandbox, c\u1ea7n th\u00eam capability <code>SYS_PTRACE<\/code> m\u1edbi d\u00f9ng \u0111\u01b0\u1ee3c strace<\/li>\n<li>Khi trace nhi\u1ec1u ti\u1ebfn tr\u00ecnh con c\u00f9ng l\u00fac, output s\u1ebd xen l\u1eabn \u2014 k\u1ebft h\u1ee3p <code>-ff -o<\/code> \u0111\u1ec3 t\u00e1ch log t\u1eebng process<\/li>\n<\/ul>\n<div class=\"warn\"><strong>B\u1ea3o m\u1eadt:<\/strong> Do ptrace ho\u1ea1t \u0111\u1ed9ng \u1edf m\u1ee9c kernel, ph\u1ea7n m\u1ec1m \u0111\u1ed9c h\u1ea1i c\u0169ng c\u00f3 th\u1ec3 d\u00f9ng c\u00f9ng c\u01a1 ch\u1ebf n\u00e0y \u0111\u1ec3 inject code v\u00e0o ti\u1ebfn tr\u00ecnh kh\u00e1c. M\u1ed9t s\u1ed1 distro c\u00f3 module b\u1ea3o m\u1eadt Yama gi\u1edbi h\u1ea1n ptrace \u2014 ki\u1ec3m tra b\u1eb1ng <code>cat \/proc\/sys\/kernel\/yama\/ptrace_scope<\/code>. Gi\u00e1 tr\u1ecb 1 ho\u1eb7c cao h\u01a1n ngh\u0129a l\u00e0 ch\u1ec9 process cha m\u1edbi trace \u0111\u01b0\u1ee3c process con.<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Cau-hoi-thuong-gap\"><\/span>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"strace-khac-ltrace-o-diem-nao\"><\/span>strace kh\u00e1c ltrace \u1edf \u0111i\u1ec3m n\u00e0o?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>strace theo d\u00f5i <strong>system call<\/strong> \u2014 giao ti\u1ebfp tr\u1ef1c ti\u1ebfp v\u1edbi Linux kernel. ltrace theo d\u00f5i <strong><a href=\"https:\/\/interdata.vn\/blog\/thu-vien-library-trong-lap-trinh\/\">library<\/a> call<\/strong> \u2014 l\u1eddi g\u1ecdi \u0111\u1ebfn c\u00e1c h\u00e0m trong shared library nh\u01b0 <code>libc<\/code>. Trong th\u1ef1c t\u1ebf, strace cho b\u1ee9c tranh t\u1ed5ng th\u1ec3 v\u1ec1 t\u01b0\u01a1ng t\u00e1c v\u1edbi OS, c\u00f2n ltrace h\u1eefu \u00edch h\u01a1n khi debug logic \u1edf t\u1ea7ng th\u01b0 vi\u1ec7n.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Co-the-dung-strace-de-debug-script-Python-hoac-Nodejs-khong\"><\/span>C\u00f3 th\u1ec3 d\u00f9ng strace \u0111\u1ec3 debug script Python ho\u1eb7c Node.js kh\u00f4ng?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u0110\u01b0\u1ee3c, nh\u01b0ng c\u00f3 gi\u1edbi h\u1ea1n. strace th\u1ea5y system call \u1edf t\u1ea7ng OS \u2014 <code>read<\/code>, <code>write<\/code>, <code>socket<\/code>, <code>mmap<\/code>&#8230; \u2014 ch\u1ee9 kh\u00f4ng th\u1ea5y logic Python\/JavaScript b\u00ean trong. H\u1eefu \u00edch khi \u1ee9ng d\u1ee5ng g\u1eb7p l\u1ed7i quy\u1ec1n file, k\u1ebft n\u1ed1i m\u1ea1ng b\u1ecb t\u1eeb ch\u1ed1i, ho\u1eb7c c\u1ea7n xem n\u00f3 \u0111\u1ecdc\/ghi file n\u00e0o. Kh\u00f4ng thay th\u1ebf \u0111\u01b0\u1ee3c debugger ng\u00f4n ng\u1eef cho vi\u1ec7c trace lu\u1ed3ng code.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"strace-tra-ve-1-nghia-la-gi\"><\/span>strace tr\u1ea3 v\u1ec1 -1 ngh\u0129a l\u00e0 g\u00ec?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 <code>-1<\/code> ngh\u0129a l\u00e0 system call th\u1ea5t b\u1ea1i. K\u00e8m theo s\u1ebd c\u00f3 m\u00e3 l\u1ed7i d\u1ea1ng <code>ERRNO (m\u00f4 t\u1ea3)<\/code>, v\u00ed d\u1ee5 <code>-1 ENOENT (No such file or directory)<\/code> ho\u1eb7c <code>-1 EACCES (Permission denied)<\/code>. \u0110\u00e2y l\u00e0 \u0111i\u1ec3m c\u1ea7n t\u1eadp trung khi debug.<\/p>\n<div class=\"cta-box\">\n<p><span style=\"font-size: 130%; color: #ed1c24;\"><strong>C\u1ea7n t\u01b0 v\u1ea5n gi\u1ea3i ph\u00e1p VPS ho\u1eb7c <a href=\"https:\/\/interdata.vn\/blog\/cloud-server-may-chu-dam-may\/\">Cloud Server<\/a> cho doanh nghi\u1ec7p?<\/strong><\/span><\/p>\n<p>\u0110\u1ed9i ng\u0169 k\u1ef9 thu\u1eadt InterData h\u1ed7 tr\u1ee3 24\/7, t\u1eeb c\u1ea5u h\u00ecnh server \u0111\u1ebfn t\u1ed1i \u01b0u h\u1ec7 th\u1ed1ng Linux.<\/p>\n<p>\ud83d\udcde <strong>1900 636 822<\/strong> | \ud83c\udf10 <strong><a href=\"https:\/\/interdata.vn\">interdata.vn<\/a><\/strong> | \ud83d\udcd8 <strong><a href=\"https:\/\/www.facebook.com\/interdata.com.vn\" target=\"_blank\" rel=\"noopener\">facebook.com\/interdata.com.vn<\/a><\/strong><\/p>\n<\/div>\n<p><strong>K\u1ebft lu\u1eadn<\/strong><\/p>\n<p>strace kh\u00f4ng ph\u1ea3i c\u00f4ng c\u1ee5 d\u00f9ng h\u00e0ng ng\u00e0y, nh\u01b0ng \u0111\u00fang l\u00fac c\u1ea7n \u2014 khi ch\u01b0\u01a1ng tr\u00ecnh im l\u1eb7ng ch\u1ebft, khi ti\u1ebfn tr\u00ecnh treo kh\u00f4ng r\u00f5 l\u00fd do, khi config &#8220;\u0111\u00fang&#8221; nh\u01b0ng kh\u00f4ng ch\u1ea1y \u2014 n\u00f3 l\u00e0 th\u1ee9 ti\u1ebft ki\u1ec7m nhi\u1ec1u gi\u1edd \u0111o\u00e1n m\u00f2 nh\u1ea5t. \u0110i\u1ec3m m\u1ea1nh c\u1ed1t l\u00f5i l\u00e0 kh\u00f4ng c\u1ea7n source code, kh\u00f4ng c\u1ea7n recompile, attach \u0111\u01b0\u1ee3c v\u00e0o b\u1ea5t k\u1ef3 ti\u1ebfn tr\u00ecnh n\u00e0o \u0111ang ch\u1ea1y.<\/p>\n<p>\u0110\u1ec3 khai th\u00e1c strace hi\u1ec7u qu\u1ea3: lu\u00f4n d\u00f9ng <code>-e trace=<\/code> \u0111\u1ec3 l\u1ecdc nh\u00f3m li\u00ean quan thay v\u00ec xem to\u00e0n b\u1ed9 output, k\u1ebft h\u1ee3p <code>grep ENOENT\\|EACCES<\/code> \u0111\u1ec3 t\u00ecm l\u1ed7i nhanh, v\u00e0 <code>-c<\/code> khi c\u1ea7n ph\u00e2n t\u00edch hi\u1ec7u n\u0103ng. Ba thao t\u00e1c n\u00e0y x\u1eed l\u00fd \u0111\u01b0\u1ee3c 80% t\u00ecnh hu\u1ed1ng debug th\u1ef1c t\u1ebf.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udccc T\u00d3M T\u1eaeT: strace l\u00e0 c\u00f4ng c\u1ee5 d\u00f2ng l\u1ec7nh tr\u00ean Linux d\u00f9ng \u0111\u1ec3 ghi l\u1ea1i to\u00e0n b\u1ed9 system call (l\u1eddi g\u1ecdi h\u1ec7 th\u1ed1ng) v\u00e0 signal m\u00e0 m\u1ed9t ti\u1ebfn tr\u00ecnh th\u1ef1c hi\u1ec7n \u2014 kh\u00f4ng c\u1ea7n source code, kh\u00f4ng c\u1ea7n recompile. B\u00e0i vi\u1ebft n\u00e0y g\u1ed3m: L\u1ec7nh strace trong Linux l\u00e0 g\u00ec, ho\u1ea1t \u0111\u1ed9ng d\u1ef1a tr\u00ean c\u01a1 ch\u1ebf<\/p>\n","protected":false},"author":11,"featured_media":41517,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[140,161],"tags":[],"class_list":["post-41495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lap-trinh","category-huong-dan-chung"],"_links":{"self":[{"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/posts\/41495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/comments?post=41495"}],"version-history":[{"count":3,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/posts\/41495\/revisions"}],"predecessor-version":[{"id":41525,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/posts\/41495\/revisions\/41525"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/media\/41517"}],"wp:attachment":[{"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/media?parent=41495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/categories?post=41495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/interdata.vn\/blog\/wp-json\/wp\/v2\/tags?post=41495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}