{"id":1428,"date":"2015-06-27T00:01:18","date_gmt":"2015-06-27T07:01:18","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=1428"},"modified":"2015-07-04T07:10:47","modified_gmt":"2015-07-04T14:10:47","slug":"know-your-process","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=1428","title":{"rendered":"Know Your Process"},"content":{"rendered":"<p>Program. Software. Application. Process. These are all terms that describe different aspects of a similar thing.<br \/>\n<!--more--><br \/>\nSoftware is the big category. Application is being redefined, thanks to mobile devices, although for a computer I use the term to refer to a software category, such as word processing.<\/p>\n<p>A program is code designed to do something, although a single program can involve many different things happening at once. That&#8217;s where the term <em>process<\/em> comes into play.<\/p>\n<p>A process is a task performed in a computer. The operating system manages all the different processes, which run at the same time in a manner I shan&#8217;t bother describing.<\/p>\n<p>When you code a C program, you&#8217;re creating something that runs as a single process. Start the program and the operating system launches the process, assigning it an ID and managing its resources.<\/p>\n<p>To view your program&#8217;s process ID, use the <em>getpid()<\/em> function. The function returns an integer value of the <em>pid_t<\/em> type and it requires inclusion of the <code>unistd.h<\/code> header file. Here&#8217;s sample code:<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;unistd.h&gt;\r\n\r\nint main()\r\n{\r\n    pid_t process;\r\n\r\n    process = getpid();\r\n    printf(\"This program has a process ID of %d\\n\",process);\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The <em>getpid()<\/em> function fetches the assigned process ID. The result is displayed, similar to this output:<\/p>\n<pre><code>This program has a process ID of 900<\/code><\/pre>\n<p>Of course, the process ID number differs from system to system, and it may change each time you run the code, but it&#8217;s unique for each running process.<\/p>\n<p>While this information may seem nice and all that, it does serve a purpose: Your program need not limit itself to a single process. It&#8217;s entirely possible for one program to run multiple processes. The process ID is how you keep track of each one. In <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=1395\">next week&#8217;s Lesson<\/a>, I&#8217;ll present code that runs two different processes &mdash; essentially a single program that multitasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The big deal on programs and processes. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=1428\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1428","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1428"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1428\/revisions"}],"predecessor-version":[{"id":1446,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1428\/revisions\/1446"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}