Life Cycle of a Process [Operating System] <div dir="ltr" style="text-align: left;" trbidi="on"><h2 style="text-align: center;"><span class="Apple-style-span" style="color: #3d85c6; font-family: 'Trebuchet MS', sans-serif;">Life Cycle of a Process</span></h2><h3 style="text-align: left;"><span style="font-family: Trebuchet MS, sans-serif;"><span style="font-weight: normal;"><span style="color: #93c47d;">Goal:- </span>How a process changes its state while execution ?</span></span></h3><h3 style="text-align: left;"><span class="Apple-style-span" style="color: #93c47d; font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Explanation:- </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">As we know a program in execution is a process.As a process </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">executes it changes state. The state of the process is defined by the current activity of that process. Each process may be in one of the following states:- </span></span></h3><h3 style="text-align: left;"><ol style="text-align: left;"><li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">New</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Ready</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Running</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Waiting</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Terminated</span></span></li> </ol><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">The above five states are standard states for a process in which a process remain in their life cycle.These states are found on all systems but there can be difference of naming conventions.Except of these states there are two more states which we will discuss in this post. They are</span></span></h3><h3 style="text-align: left;"><ol style="text-align: left;"><li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Suspended Ready</span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Suspended Wait.</span></li> </ol><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Figure-1 Shows the life cycle of a Process:-</span></span></h3><div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody> <tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVJGs5AWGCvvczYOg_zghIQ0baLt-Kaj1K2Zi_y2k-ogYAP8qVE2cCkyA52Ilo2yfgNDbbNWSKlMr20EjFhuYEGMlNN9kLI4M9Gso2GDKBhy9zwfmoAhn61xhzIbN4GlsodO9IhRnzF9FU/s1600/process.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="347" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVJGs5AWGCvvczYOg_zghIQ0baLt-Kaj1K2Zi_y2k-ogYAP8qVE2cCkyA52Ilo2yfgNDbbNWSKlMr20EjFhuYEGMlNN9kLI4M9Gso2GDKBhy9zwfmoAhn61xhzIbN4GlsodO9IhRnzF9FU/s1600/process.png" width="640" /></a></td></tr> <tr><td class="tr-caption" style="text-align: center;">Figure-1 States of a Process<br /> <br /> </td></tr> </tbody></table><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br /> <!-- between_post2 --><br /> <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1000631018247743" data-ad-slot="8769746517"></ins><br /> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><br /> <span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-size: 19px;">Now we will start with description of each state:-</span></div><div><h3><ol style="text-align: left;"><li><span class="Apple-style-span" style="color: #6aa84f; font-family: 'Trebuchet MS', sans-serif;">New:- </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">If the process is in new state that means either the process is under creation or is being created.</span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="color: #6aa84f;">Ready:-</span><span class="Apple-style-span" style="font-weight: normal;"><span class="Apple-style-span" style="color: #6aa84f;"> </span>After the successful creation of a process, it is placed in Ready state by Long Term Scheduler. In this state process will wait to be assigned to a processor.In this state we can have <span class="Apple-style-span" style="color: red;">a multiple no. of processes.</span></span></span></li> <li><span class="Apple-style-span" style="color: #6aa84f; font-family: 'Trebuchet MS', sans-serif;">Running:- </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">From the Ready state one of the process is selected and it will be scheduled or Dispatched to the Running State by Short Term Scheduler. If a process is in Running state that means instructions of the process are being executed. ****Only <span class="Apple-style-span" style="color: red;">one process will reside in memory(Running State)</span> at any point of time.</span></span></li> <li><span class="Apple-style-span" style="color: #6aa84f; font-family: 'Trebuchet MS', sans-serif;">Waiting:-</span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"> <span class="Apple-style-span" style="font-weight: normal;">If any running process require any input/output operation the process will be moved into wait state. ** In wait state, multiple process are there. Multiple process will perform their I/O simultaneously.</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="color: #6aa84f;">Terminated:- </span><span class="Apple-style-span" style="font-weight: normal;">The Process has finished execution.</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"></span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="color: #6aa84f;">Suspended Ready:- </span></span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">When the large no. of process are created and resources are short enough to manage the process then some of the process will be suspended and moved to suspended ready state. Whenever the resources are sufficient the process are resume back to the ready state by Mid term Scheduler.</span></span></li> <li><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="color: #6aa84f;">Suspended Wait:- </span><span class="Apple-style-span" style="font-weight: normal;"> When resources are short enough to manage the process in wait/block state then some of the process will be suspended and moved to suspended block state. Whenever the resources are sufficient the process are resume back to the wait state by MTS. </span></span></li> </ol><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">-->**When the Process is in Suspended Ready or Suspended wait, it reside in secondary memory or Backing Store.</span></span></h3><h3 style="text-align: left;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;">So this is all about Life cycle of a process and if I really helped you please let me know via comment.</span></h3></div><div><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><br /> </span></div><div><h3 style="background-color: white; color: #333333; font-family: Bitter, serif, sans-serif; font-weight: normal; margin: 0px 0px 10px;"><span style="font-size: large;"><span style="color: red; line-height: 19.1875px;">If you want to share more information about topic discussed above or find anything incorrect Please do comments.</span> </span></h3></div><span style="font-family: Bitter, serif, sans-serif; font-size: large;"><b style="color: #333333;">For more Concepts Stay Connected</b><span style="color: #333333;">..</span><a href="http://www.facebook.com/codieehome" target="_blank"><span style="color: red;">Like</span></a><span style="color: #333333;"> us on Facebook.</span></span></div> Life Cycle of a Process [Operating System] Life Cycle of a Process Goal:- How a process changes its state while execution ? Explanation:- As we know a program in execution is a proces... + Read more »
How to do[Implement] Swipe in Android[In Eclipse] <div dir="ltr" style="text-align: left;" trbidi="on"> <h2 style="text-align: center;"> <span class="Apple-style-span" style="color: #3d85c6; font-family: 'Trebuchet MS', sans-serif;">How to do Swipe in Android</span></h2> <h3 style="text-align: justify;"> <span style="font-family: Trebuchet MS, sans-serif;"><span style="font-weight: normal;"><span style="color: #93c47d;">Goal:- </span>Detecting swipe events in Android ?</span></span></h3> <h3 style="text-align: justify;"> <span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-style-span" style="color: #93c47d; font-weight: normal;">Explanation:- </span><span class="Apple-style-span" style="font-weight: normal;">Android supports eight gestures and Swipe is one of them which is mostly used in apps. A swipe event generally occurs when you drag your hand on screen from one point to another.Sometimes Swipe is considered same as drag but there is some differences between them-</span></span></h3> <h3 style="text-align: justify;"> <span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-style-span" style="font-weight: normal;"> 1. Swipe is faster than drag.</span></span></h3> <h3 style="text-align: justify;"> <span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-style-span" style="font-weight: normal;"> 2. Drag stops affecting screen when you remove your finger from screen but in case of swipe it affect the screen even after the finger is removed. </span></span></h3> <h3 style="text-align: justify;"> <span style="font-family: Trebuchet MS, sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Without getting much in swipe's intro, i am starting with the actual thing for which you are here. To implement swipe in your app, you don't have to do much coding. Because Android provides you a GestureDetector class which detects all types of gesture. It supports the gestures like onDown(), onLongPress(), onFling() but swipe is handled by onFling(). </span></span></h3> <h3 style="text-align: justify;"> <span class="Apple-style-span" style="color: #93c47d; font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Steps:- </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">So here is the simple steps of implementing Swipe in your App:-</span></h3> <h3 style="text-align: left;"> <ol style="text-align: left;"> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Implement OnGestureListener() interface.</span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Now you will see a warning sign in your eclipse, click on that and implement all abstract methods.</span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Look for the function named onFling().</span></span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">onFling() function accept four arguments in which first two are of Motion type and Last two are of float type.</span></span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">first and second argument represent the first(when you first touch the screen)</span></span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;"> and last(when you release the screen) </span><span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="font-size: small;">touch events (position, pressure, size, addition of another finger, etc.)<span class="Apple-style-span" style="font-weight: normal;"> </span></span></span><span class="Apple-style-span" style="font-weight: normal;">respectively.</span></span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">Last two arguments represents the velocities along X-axis and Y-axis respectively.</span></span></li> <li style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;">You also need to create a object of GestureDetector to get information about the gesture happened.</span></span></li> </ol> </h3> <div> <div style="text-align: justify;"> <span class="Apple-style-span" style="color: #93c47d; font-family: 'Trebuchet MS', sans-serif; font-size: 19px;">Program:-</span></div> </div> <div style="font-size: 15px; text-align: justify;"> <br /></div> <div style="text-align: justify;"> <script class="brush:java" type="syntaxhighlighter"> package com.example.gesture; import android.os.Bundle; import android.app.Activity; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.Menu; import android.view.MotionEvent; import android.widget.Toast; public class MainActivity extends Activity implements OnGestureListener { private int AJ=100; //AJ is a threshold value which specifies the length of your swipe. private GestureDetector gd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gd = new GestureDetector(getApplicationContext(),MainActivity.this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onDown(MotionEvent arg0) { return false; } @Override public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,float arg3) { if((arg0.getX()-arg1.getX())>AJ) //calculating if the swipe length is more than threshold or not { Toast.makeText(MainActivity.this,"LeftSwipe",Toast.LENGTH_LONG).show(); } if((arg1.getX()-arg0.getX())>AJ) { Toast.makeText(MainActivity.this,"RightSwipe",Toast.LENGTH_LONG).show(); } if((arg0.getY()-arg1.getY())>AJ) { Toast.makeText(MainActivity.this,"UpSwipe",Toast.LENGTH_LONG).show(); } if((arg1.getY()-arg0.getY())>AJ) { Toast.makeText(MainActivity.this,"DownSwipe",Toast.LENGTH_LONG).show(); } return false; } @Override public void onLongPress(MotionEvent arg0) { // TODO Auto-generated method stub } @Override public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent arg0) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent arg0) { // TODO Auto-generated method stub return false; } //this method is called when we place our finger on the screen. // check the return value of method, in this program it is the only method where we use our Gesture detector object. @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return gd.onTouchEvent(event); } } </script><br /></div> <h3 style="font-size: 19px; text-align: justify;"> <span class="Apple-style-span" style="color: #93c47d; font-family: 'Trebuchet MS', sans-serif;"><span class="Apple-style-span" style="font-weight: normal;"><br /> </span></span></h3> <div> <h3 style="text-align: justify;"> <span class="Apple-style-span" style="color: #93c47d; font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">Output:- </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;"> I don't think that there is a need of uploading the output of this program.When you run this app there is blank screen because we didn't add any component in layout file. When you swipe the screen then there will be a toast message specifying the type of your swipe.</span></h3> <h3 style="text-align: justify;"> <span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;"></span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;"> *In the toast message Toast.LENGTH_LONG is used so you need to wait for next toast message. </span></h3> <h3 style="text-align: justify;"> <span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">*If you face any problem in implementing this code ,tell me via comments.</span></h3> <div> <span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-weight: normal;">* </span><span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-size: 19px;">If you need any program or any help in programming then <span class="Apple-style-span" style="color: #93c47d;"><a href="http://codieehome.blogspot.com/p/contact-us_15.html" target="_blank">Request Here</a> </span></span></div> <div> <span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif; font-size: 19px;"><br /></span></div> <h3 style="background-color: white; color: #333333; font-family: Bitter, serif, sans-serif; font-size: 19px; font-weight: normal; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: justify;"> <span style="font-size: large;"><span style="color: red; line-height: 19.1875px;">If you want to share more information about topic discussed above or find anything incorrect Please do comments.</span> </span></h3> <div style="font-size: 19px;"> <div style="text-align: justify;"> <span style="font-family: Bitter, serif, sans-serif; font-size: large;"><b style="color: #333333;">For more Programs Stay Connected</b><span style="color: #333333;">..</span><a href="http://www.facebook.com/codieehome" target="_blank"><span style="color: red;">Like</span></a><span style="color: #333333;"> us on Facebook.</span></span></div> </div> </div> </div> How to do[Implement] Swipe in Android[In Eclipse] How to do Swipe in Android Goal:- Detecting swipe events in Android ? Explanation:- Android supports eight gestures and Swipe is o... + Read more »