{"id":1096,"date":"2020-10-17T14:58:39","date_gmt":"2020-10-17T14:58:39","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1096"},"modified":"2020-10-17T14:58:52","modified_gmt":"2020-10-17T14:58:52","slug":"kernel-mode","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/10\/17\/kernel-mode\/","title":{"rendered":"Kernel Mode"},"content":{"rendered":"\n<p>The CPU operates in two modes in Linux<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>User mode (non privileged mode)<\/li><li>Kernel mode (System mode)<\/li><\/ol>\n\n\n\n<p>When operating in Kernel mode it has un-restricted access to resources like memory and input output devices.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-solid-color\"><blockquote><p>Kernel is a trusted software and all other programs are treated as untrusted softwares.<\/p><\/blockquote><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Mode switch<\/h2>\n\n\n\n<p>All processes start execution in the user mode, and they switch to kernel mode only when obtaining a service provided by the kernel. This change in mode is termed a\u00a0<em>mode switch<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-solid-color\"><blockquote><p>A\u00a0<em>system call<\/em>, sometimes referred to as a\u00a0<em>kernel call<\/em><\/p><cite>system call<\/cite><\/blockquote><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How does the interaction happen?<\/h2>\n\n\n\n<p>Ever so often the user mode program needs to access a privileged resource and that happens via system calls.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-solid-color\"><blockquote><p>A system call is a request to the kernel by an\u00a0<em>active process<\/em>\u00a0for a service performed by the kernel.\u00a0<\/p><\/blockquote><\/figure>\n\n\n\n<p>When a user process runs a portion of the kernel code via a system call, the process temporarily shifts into the kernel mode.\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preemptive vs non-preemptive<\/h2>\n\n\n\n<p>A preemptive task can be interrupted before it completes its function whereas a non preemptive task cannot be interrupted before it completes its task.<\/p>\n\n\n\n<p>Process in kernel mode can be interrupted by an\u00a0<em>interrupt<\/em>\u00a0or an\u00a0<em>exception<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-solid-color\"><blockquote><p>A process in kernel mode cannot be arbitrarily suspended and replaced by another process for the duration of its\u00a0<em>time slice<\/em><\/p><cite>Preempted<\/cite><\/blockquote><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The CPU operates in two modes in Linux User mode (non privileged mode) Kernel mode (System mode) When operating in Kernel mode it has un-restricted access to resources like memory and input output devices. Kernel is a trusted software and all other programs are treated as untrusted softwares. Mode switch All processes start execution in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1097,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[112,119,118],"class_list":["post-1096","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-linux","tag-refresher","tag-tips","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1096"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1096\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1097"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}