{"id":473,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:16","modified_gmt":"2020-08-22T20:26:16","slug":"this-is-the-page-title-toplevel-306","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=473","title":{"rendered":"Linux Processes"},"content":{"rendered":"\n<title>Linux Processes<\/title>\n<p>\nSo that Linux can manage the processes in  the system, each process is represented by a\n<tt>task_struct<\/tt>  data structure\n(task and process are terms that Linux uses interchangeably).\nThe <tt>task<\/tt> vector is an array of pointers to every <tt>task_struct<\/tt> data\nstructure in the system.\n<p>\nThis means that the maximum number of processes in the system is limited by the\nsize of the <tt>task<\/tt> vector; by default it has 512 entries.\nAs processes are created, a new <tt>task_struct<\/tt> is allocated from system memory\nand added into the <tt>task<\/tt> vector.\nTo make it easy to find, the current, running, process is pointed to by the <tt>current<\/tt> pointer.\n<p>\nAs well as the normal type of process, Linux supports real time processes.\nThese processes have to react very quickly to external events (hence the term &#8220;real time&#8221;)\nand they are treated differently from normal user processes by the scheduler.\nAlthough the <tt>task_struct<\/tt> data structure is quite large and complex, but its fields\ncan be divided into a number of functional areas:\n<dl compact>\n<p>\n\t<dt><b>State<\/b><\/dt>\n        <dd> As a process executes it changes <em>state<\/em> according to its circumstances.\n\t\tLinux processes have the following states:\n\t\t<a href=\"#tthFtNtAAB\" name=tthFrefAAB><sup>1<\/sup><\/a>\n<dl compact>\n\t\t<dt><b>Running<\/b><\/dt><dd> The process is either running (it is the current process in the\n\t\t\tsystem) or it is ready to run (it is waiting to be assigned to one of\n\t\t\tthe system&#8217;s CPUs).\n\t\t<dt><b>Waiting<\/b><\/dt><dd> The process is waiting for an event or for a resource.  Linux\n\t\t\tdifferentiates between two types of waiting process; <em>interruptible<\/em>\n\t\t\tand <em>uninterruptible<\/em>.   Interruptible waiting processes can be\n\t\t\tinterrupted by signals whereas uninterruptible waiting processes are waiting\n\t\t\tdirectly on hardware conditions and cannot be interrupted under any\n\t\t\tcircumstances.\n\t\t<dt><b>Stopped<\/b><\/dt><dd> The process has been stopped, usually by receiving a signal.  A process\n\t\t\tthat is being debugged can be in a stopped state.\n\t\t<dt><b>Zombie<\/b><\/dt><dd> This is a halted process which, for some reason, still has a\n\t\t\t<tt>task_struct<\/tt> data structure in the <tt>task<\/tt> vector.  It is what it\n\t\t\tsounds like, a dead process.\n\t\t<\/dl>\n<p>\n\t<dt><b>Scheduling Information<\/b><\/dt><dd> The scheduler needs this information in order\n\tto fairly decide which process in the system most deserves to run,\n<p>\n\t<dt><b>Identifiers<\/b><\/dt><dd> Every process in the system has a process identifier.\n\tThe process identifier is not an index into the\n\t<tt>task<\/tt> vector, it is simply a number.  Each process also has\n\tUser and group identifiers, these are used to control this processes access to the files and\n\tdevices in the system,\n<p>\n\t<dt><b>Inter-Process Communication<\/b><\/dt><dd> Linux supports the classic Unix <sup><font size=-4><tt>T<\/tt>M<\/font><\/sup>&nbsp;IPC mechanisms of\n\tsignals, pipes and semaphores and also the System V IPC mechanisms of shared memory,\n\tsemaphores and message queues.\n\tThe IPC mechanisms supported by Linux are described in the <site id=\"288\">section on IPC<\/site>.\n<p>\n\t<dt><b>Links<\/b><\/dt><dd> In a Linux system no process is independent of any other process.\n\tEvery process in the system, except the initial process has a parent process.\n\tNew processes are not created, they are copied, or rather <em>cloned<\/em> from previous processes.\n\tEvery <tt>task_struct<\/tt> representing a process keeps pointers to its parent process\n\tand to its siblings (those processes with the same parent process) as well as to its own child\n\tprocesses.\n\tYou can see the family relationship between the running processes in a Linux system\n\tusing the <font face=\"helvetica\">pstree<\/font> command:\n<pre>\ninit(1)-+-crond(98)\n        |-emacs(387)\n        |-gpm(146)\n        |-inetd(110)\n        |-kerneld(18)\n        |-kflushd(2)\n        |-klogd(87)\n        |-kswapd(3)\n        |-login(160)---bash(192)---emacs(225)\n        |-lpd(121)\n        |-mingetty(161)\n        |-mingetty(162)\n        |-mingetty(163)\n        |-mingetty(164)\n        |-login(403)---bash(404)---pstree(594)\n        |-sendmail(134)\n        |-syslogd(78)\n        `-update(166)\n<\/pre>\n\tAdditionally all of the processes in the system are held in a doubly linked list\n\twhose root is the <tt>init<\/tt> processes <tt>task_struct<\/tt> data structure.\n\tThis list allows the Linux kernel to look at every process in the system.\n\tIt needs to do this to provide support for commands such as <font face=\"helvetica\">ps<\/font> or <font face=\"helvetica\">kill<\/font>.\n<p>\n\t<dt><b>Times and Timers<\/b><\/dt><dd> The kernel keeps track of a processes creation time as well as the\n\tCPU time that it consumes during its lifetime.  Each clock tick, the\n\tkernel updates the amount of time in <tt>jiffies<\/tt> that the current process\n\thas spent in system and in user mode.\n\tLinux also supports process specific <em>interval<\/em> timers, processes can use system\n\tcalls to set up timers to send signals to themselves when the timers expire.\n\tThese timers can be single-shot or periodic timers.\n<p>\n\t<dt><b>File system<\/b><\/dt><dd> Processes can open and close files as they wish and the\n\tprocesses <tt>task_struct<\/tt>\n\tcontains pointers to descriptors for each open file as well as pointers to two\n\tVFS inodes.\n\tEach VFS inode uniquely describes a file or directory within a file system and also\n\tprovides a uniform interface to the underlying file systems.\n\tHow file systems are supported under Linux is described in\n       the <site id=\"95\">section on the filesystems<\/site>.\n\tThe first is to the root of the process (its home directory) and the second is to its\n\tcurrent or <em>pwd<\/em> directory.  <em>pwd<\/em> is derived from the Unix <sup><font size=-4><tt>T<\/tt>M<\/font><\/sup>&nbsp;command <font face=\"helvetica\">pwd<\/font>,\n\t<em>print working directory<\/em>.\n\tThese two VFS inodes have their <tt>count<\/tt> fields incremented to show that\n\tone or more processes are referencing them.   This is why you cannot delete\n\tthe directory that a process has as its <em>pwd<\/em> directory set to, or for that\n\tmatter one of its sub-directories.\n<p>\n\t<dt><b>Virtual memory<\/b><\/dt><dd> Most processes have some virtual memory (kernel threads and\n\tdaemons do not) and the Linux kernel must track how that virtual memory is\n\tmapped onto the system&#8217;s physical memory.\n<p>\n\t<dt><b>Processor Specific Context<\/b><\/dt><dd> A process could be thought of as the sum total of the\n\tsystem&#8217;s current state.\n\tWhenever a process is running it is using the processor&#8217;s registers, stacks and\n\tso on.\n\tThis is the processes context and, when a process is suspended, all of that\n\tCPU specific context must be saved in the <tt>task_struct<\/tt> for the process.\n\tWhen a process is restarted by the scheduler its context is restored from here.\n<p>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Linux Processes So that Linux can manage the processes in the system, each process is represented by a task_struct data structure (task and process are terms that Linux uses interchangeably). The task vector is an array of pointers to every &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=473\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-473","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=473"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/473\/revisions"}],"predecessor-version":[{"id":608,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/473\/revisions\/608"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}