RSA algorithm in the SSL - rsa

I want to know about the explanation of RSA, here is the example
Select primes: p=17 & q=11
Compute n = pq =17×11=187
Compute ø(n)=(p–1)(q-1)=16×10=160
Select e : gcd(e,160)=1; choose e=7
Determine d: de=1 mod 160 and d < 160 Value is d=23 since 23×7=161= 10×160+1
Publish public key KU={7,187}
Keep secret private key KR={23,17,11}
Look at the prime numbers written above, how can i know from where those prime numbers are generated.

Those prime numbers can be generated randomly by the RSA algorithm. In this example they are very small, but in real life the would be very very large. The algorithm will also take some other precautions when generating the primes. For instance, p and q should not be close to one another.

here is the code that implements RSA
try out this code
/*Arpana*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long int p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
int prime(long int);
void ce();
long int cd(long int);
void encrypt();
void decrypt();
void main()
{
clrscr();
printf("\nENTER FIRST PRIME NUMBER\n");
scanf("%d",&p);
flag=prime(p);
if(flag==0)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER ANOTHER PRIME NUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER MESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
}
int prime(long int pr)
{
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{
if(pr%i==0)
return 0;
}
return 1;
}
void ce()
{
int k;
k=0;
for(i=2;i<t;i++)
{
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
{
e[k]=i;
flag=cd(e[k]);
if(flag>0)
{
d[k]=flag;
k++;
}
if(k==99)
break;
}
}
}
long int cd(long int x)
{
long int k=1;
while(1)
{
k=k+t;
if(k%x==0)
return(k/x);
}
}
void encrypt()
{
long int pt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len)
{
pt=m[i];
pt=pt-96;
k=1;
for(j=0;j<key;j++)
{
k=k*pt;
k=k%n;
}
temp[i]=k;
ct=k+96;
en[i]=ct;
i++;
}
en[i]=-1;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt()
{
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1)
{
ct=temp[i];
k=1;
for(j=0;j<key;j++)
{
k=k*ct;
k=k%n;
}
pt=k+96;
m[i]=pt;
i++;
}
m[i]=-1;
printf("\nTHE DECRYPTED MESSAGE IS\n");
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}

Related

Sort an array A using Quick Sort. Using reccursion

#include<iostream>
using namespace std;
void quickSort(int input[], int start, int end)
{
// your code goes here
}
void quickSort(int input[], int size)
{
quickSort(input, 0, size - 1);
}
*/
void swap(int* a,int* b){
int temp=*a;
*a=*b;
*b=temp;
}
int count(int input[],int start,int end ){
static int c=0;
if(start==end)
return c;
if(input[start]>input[end])
c++;
return count(input,start,end-1);
}
int partionArray(int input[],int start,int end ){
int c=count(input,start,end);
int pi=c+start;
swap(&input[start],&input[pi]);
int i=start;
int j=end;
while(i<pi&&j>pi)
{
if(input[i]<input[pi])
{
i++;
}
else if(input[j]>=input[pi])
{
j--;
}
else
{
swap(&input[i],&input[j]);
i++;
j--;
}
}
return pi;
}
void qs(int input[],int start, int end){
if(start>=end)
return;
int pi=partionArray(input,start,end);
qs(input,start,pi-1);
qs(input,pi+1,end);
}
void quickSort(int input[], int size) {
qs(input,0,size-1);
}
int main(){
int n;
cin >> n;
int *input = new int[n];
for(int i = 0; i < n; i++) {
cin >> input[i];
}
quickSort(input, n);
for(int i = 0; i < n; i++) {
cout << input[i] << " ";
}
delete [] input;
}
Sort an array A using Quick Sort. Using reccursion is the question.
Input format :
Line 1 : Integer n i.e. Array size
Line 2 : Array elements (separated by space)
Output format :
Array elements in increasing order (separated by space)
Constraints :
1 <= n <= 10^3
What did i do wrong in this code pls can any one explain?Is every thing right with this code?

Backtrack the difference between these two codes

I have been trying to play around with backtracking. From my understanding these two codes are doing same thing but somehow I got different outcomes.
I am just trying to use some type of template to start with.
cout<<i<<endl;
backtrack(i+1);
backtrack(i+1);
and
for(int i=start; i<n; i++){
cout<<i<<endl;
backtrack(i+1);
}
The first one gets 5 as outcome and the second one gets six when I have the input of
nums=[1,1,1,1,1]
target = 3
public class Solution {
int count = 0;
public int findTargetSumWays(int[] nums, int S) {
calculate(nums, 0, 0, S);
return count;
}
public void calculate(int[] nums, int i, int sum, int S) {
if (i == nums.length) {
if (sum == S) {
count++;
}
} else {
calculate(nums, i + 1, sum + nums[i], S);
calculate(nums, i + 1, sum - nums[i], S);
}
}
}
class Solution {
public:
int count;
void backtrack(vector<int>& nums, int target, int start, int sum){
if(start==nums.size()){
if(sum==target){
count++;
}
return;
}
else{
for(int i=start; i<nums.size(); i++){
//sum+=nums[i];
backtrack(nums, target, i+1, sum+nums[i]);
sum-=nums[i];
}
}
}
int findTargetSumWays(vector<int>& nums, int target) {
count=0;
int sum=0;
int total=0;
for(auto x:nums)total+=x;
vector<vector<int>> dp;
backtrack(nums, target, 0, sum);
return count;
}
};

passing method name as parameter for threadpool queuserworkitem

QueUserWorkItem is supposed to accept a delegate but i found exercise that passes instance method name instead of delegate like this:
public class Fibonacci
{
private int _n;
private int _fibOfN;
private ManualResetEvent _doneEvent;
public int N { get { return _n; } }
public int FibOfN { get { return _fibOfN; } }
// Constructor.
public Fibonacci(int n, ManualResetEvent doneEvent)
{
_n = n;
_doneEvent = doneEvent;
}
// Wrapper method for use with thread pool.
public void ThreadPoolCallback(Object threadContext)
{
int threadIndex = (int)threadContext;
Console.WriteLine("thread {0} started...with id={1}", threadIndex,Thread.CurrentThread.ManagedThreadId);
_fibOfN = Calculate(_n);
Console.WriteLine("thread {0} result calculated...", threadIndex);
_doneEvent.Set();
}
// Recursive method that calculates the Nth Fibonacci number.
public int Calculate(int n)
{
if (n <= 1)
{
return n;
}
return Calculate(n - 1) + Calculate(n - 2);
}
}
public class Program
{
static void Main()
{
const int FibonacciCalculations = 10;
// One event is used for each Fibonacci object.
ManualResetEvent[] doneEvents = new ManualResetEvent[FibonacciCalculations];
Fibonacci[] fibArray = new Fibonacci[FibonacciCalculations];
Random r = new Random();
// Configure and start threads using ThreadPool.
Console.WriteLine("launching {0} tasks...", FibonacciCalculations);
for (int i = 0; i < FibonacciCalculations; i++)
{
doneEvents[i] = new ManualResetEvent(false);
Fibonacci f = new Fibonacci(r.Next(20, 40), doneEvents[i]);
fibArray[i] = f;
ThreadPool.QueueUserWorkItem(f.ThreadPoolCallback , i);
}
for (int x = 0; x < 10;x++ )
{
Console.WriteLine("x");
}
// Wait for all threads in pool to calculate.
WaitHandle.WaitAll(doneEvents);
Console.WriteLine("All calculations are complete.");
// Display the results.
for (int i = 0; i < FibonacciCalculations; i++)
{
Fibonacci f = fibArray[i];
Console.WriteLine("Fibonacci({0}) = {1}", f.N, f.FibOfN);
}
}
}
why does this work? I do not see implicit or explicit delegate being passed

Fibonacci Sequence error

I am coding a Fibonacci sequence in Eclipse and this is my code-
public class FibonacciAlgorithm {
private int a = 0;
private int b = 1;
public FibonacciAlgorithm() {
}
public int increment() {
int temp = b;
b = a + b;
a = temp;
return value;
}
public int getValue() {
return b;
}
}
It is showing an error in the return value; line saying value cannot be resolved to a variable. I don't see any other errors.
Where is value defined? You return something that was not defined anywhere.
You don't have a "value" defined, this is your error. I don't remember the thing exactly, but I think you don't need a and b, I found this in my code archive, hope it helps.
public class Fibonacci
{
public static long fibo(int n)
{
if (n <= 1) return n;
else return fibo(n - 1) + fibo(n - 2);
}
public static void main() {
int count = 5; // change accordingly, bind to input etc.
int N = Integer.parseInt(count);
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fibo(i));
}
}
In case you want to stay with your own code, try returning "b" as value.
Your method is returning an int variable so you would have to define and return value as an int
I am not sure what you trying to do.
If you have "getValue" method I think "increment" method should be void.
When you want current Fibonacci value use "getValue" method.
public class FibonacciAlgorithm {
private int a = 0;
private int b = 1;
public FibonacciAlgorithm() {
}
public void increment() {
int temp = b;
b = a + b;
a = temp;
}
public int getValue() {
return b;
}

Process Control Block

My professor asks this question for Homework.
Consult a Linux Manual or a Microsoft Windows manual. Find the actual contents of the Process Control Block (Process Descriptor) in the operating system of your choice.
I know in general PCB contains
Process number or process ID
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information
I am trying to find manual but I did not see it online. Could anybody help me with this.
From what I understand in Linux, PCB or Process Descriptors are dynamically allocated by the kernel and cannot directly be read from user-space.
IBM's developerWorks library has a nice article which shows you how to create a kernel module for Linux and access task_struct struct.
http://www.ibm.com/developerworks/linux/library/l-linux-process-management/index.html
Hope this helps.
edit: task_struct as defined in Linux v2.6.37 : http://lxr.linux.no/#linux+v2.6.37/include/linux/sched.h#L1182
Courtesy of google. :)
For Linux, start here (and go to more current versions of the Linux kernel). Though old, this should sufficiently help find your answer.
For windows, you can take a look at the user-mode equivalent called the 'PEB'. It can be inspected using WinDbg using '!peb'.
This could help you out. I previously post it but I had to cancel my account for security reasons.
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include "proc.h"
#include "rq.h"
using namespace std;
// creates a vector of Queues
void load_queue(vector<rq> &queue, unsigned int num_of_queues)
{
for(int pos=0; pos<num_of_queues; pos++)
{
queue.push_back(rq());
}
}
//returns the biggest queue position in the vector
unsigned int get_biggest_queue_pos(vector<rq> queues)
{
unsigned int queue_pos = 0; // Pos of smaller queue. Default 0.
unsigned int queue_size = queues.at(queue_pos).size(); // Its size
for(unsigned int pos = 0; pos < queues.size(); pos++)
{
if(queues.at(pos).size() > queue_size)
{
queue_pos = pos;
queue_size = queues.at(pos).size();
}
}
return queue_pos; // Return smaller queue position in vector.
}
// Returns the smaller queue position in the vector.
unsigned int get_smaller_queue_pos(vector<rq> queues)
{
unsigned int queue_pos = 0; // Pos of smaller queue. Default 0.
unsigned int queue_size = queues.at(queue_pos).size(); // Its size
for(unsigned int pos = 0; pos < queues.size(); pos++)
{
if(queues.at(pos).size() < queue_size)
{
queue_pos = pos;
queue_size = queues.at(pos).size();
}
}
return queue_pos; // Return smaller queue position in vector.
}
//Searches for a PID in entire system and erases it.
bool get_pid_process(vector<rq> &queue, int id)
{
vector <proc> temp;
proc process(0,0,0);
int check;
int number=id;
int size=queue.size();
/*checks rest of queues, including ready queues and device queues*/
for(int i=0; i<size; i++)
{
temp=queue[i].get_queue();
int size1=temp.size();
for(int j=0; j<size1; j++)
{
process=temp.at(j);
check=process.get_pid();
if(check==number)
{
cout<<"Process found in a queue and being erased..."<<endl;
queue[i].remove_process(j);
float cputime=process.get_burst();
float burstime=process.get_average();
cout<<"Process information:"<<endl;
cout<<"PID: "<<number<<endl<<"Acc CPU time: "<<cputime<<endl<<"Average burst time: "<<burstime<<endl;
cout<<"Process killed"<<endl<<endl;
return true;
}
}
}
/*Checks all CPUs in ready queues*/
for(int k=0; k<size; k++)
{
temp=queue[k].get_cpu();
process=temp.front();
check=process.get_pid();
if(check==number)
{
cout<<"Process found in a CPU and being erased..."<<endl;
float cputime=process.get_burst();
float burstime=process.get_average();
queue[k].clear_cpu();
cout<<"Process information:"<<endl;
cout<<"PID: "<<number<<endl<<"Acc CPU time: "<<cputime<<endl<<"Average burst time: "<<burstime<<endl;
cout<<"Process killed"<<endl<<endl;
return true;//ends if PID is found in CPU and returns true
}
}
return false;
}
int main()
{
cout << "Sys gen starting..."<<endl;
cout<<"Please enter the amount of CPUs (between 1 and 9)"<<endl;
int cpu;
cin>>cpu;
while(cpu<1 || cpu>9)
{
cout<<"Invalid value, please re-enter amount:"<<endl;
cin>>cpu;
}
cout<<"Enter amount of PRINTERs:"<<endl;
int pr;
cin>>pr;
cout<<"Enter amount of DISKs:"<<endl;
int di;
cin>>di;
cout<<"Enter amount of CD/RWs:"<<endl;
int cd;
cin>>cd;
int devices=(cpu*2)+pr+di+cd;//amount of devices(queues and CPU's)
int PID=0;
int PCB=0;
vector<rq> RQ; //vector of ready queues
vector<rq> PQ; //vector of printer queues
vector<rq> DQ; //vector of disk queues
vector<rq> CQ; //vector of CD/RW queues
load_queue(RQ, cpu);
load_queue(PQ, pr); //load printer queues to PQ vector
load_queue(DQ, di); // ...
load_queue(CQ, cd); // ...
cout << "Running section..." <<endl<< endl;
cout<<"Start inputting commands; To terminate program press E or e at any time:"<<endl;
while(true)
{
string device;//for name of device
string enter;//for input
cin>>enter;
int correspond=0;
int smaller;
char num11=enter[0];//1st position character
char input=enter[1];//2nd position char
char num=enter[2];//3rd position char
int num1=num11 -'0';//1st position integer
int n=num -'0';//3rd position int
int inp=input - '0';//2nd position int
int empty;
/*creates a new process and puts it into emptiest Ready Queue*/
if(num11=='A')
{
smaller=get_smaller_queue_pos(RQ); //determines which ready queue has less processes
RQ[smaller].create_process(smaller, PID, PCB);
PID++;
PCB++;
if(RQ[smaller].get_cpu().size() == 0)
{
RQ[smaller].cpu();
}
}
/*terminates a process from a particular CPU*/
else if(input=='t')
{
if(num1>0 && num1<=cpu)
{
RQ[num1-1].terminate();
PCB--;
RQ[num1-1].cpu();
}
else
{
cout<<"Invalid entry"<<endl;
}
}
/*Prints out a snapshot of a particular device Q or the ready queues*/
else if(num11 == 'S')
{
cout << "Select a queue: "<<endl;
char sele;
cin >> sele;
switch(sele)
{
case 'p':
if(pr==0)
{
cout<<"There are no printer queues created."<<endl;
}
else
{
device="Printer";
cout<<"A snapshot of your "<<device<<" queues:"<<endl<<"PCB\tPID\tLENGTH\tLOCATION\tFILE NAME\tUsed CPU time(ms)\tAverage Burst time(ms)"<<endl;
for(int i = 0; i < PQ.size(); i++)
{
cout<<device<<" "<<i+1<<":"<<endl;
PQ.at(i).snapshot(device);
}
}
break;
case 'r':
cout<<endl<<"___A Snapshot of your Ready Queue(s)___"<<endl;
for(int i = 0; i < RQ.size(); i++)
{
cout<<"Ready queue "<<i+1<<":"<<endl;
RQ[i].snapshot();
}
break;
case 'd':
if(di==0)
{
cout<<"There are no disk queues created."<<endl;
}
else
{
device="Disk";
cout<<"A snapshot of your "<<device<<" queues:"<<endl<<"PCB\tPID\tLENGTH\tLOCATION\tFILE NAME\tUsed CPU time(ms)\tAverage Burst time(ms)"<<endl;
for(int i = 0; i < PQ.size(); i++)
{
cout<<device<<" "<<i+1<<":"<<endl;
DQ.at(i).snapshot(device);
}
}
break;
case 'c':
if(cd==0)
{
cout<<"There are no cd/rw queues created."<<endl;
}
else
{
device="Cd/rw";
cout<<"A snapshot of your "<<device<<" queues:"<<endl<<"PCB\tPID\tLENGTH\tLOCATION\tFILE NAME\tUsed CPU time(ms)\tAverage Burst time(ms)"<<endl;
for(int i = 0; i < PQ.size(); i++)
{
cout<<device<<" "<<i+1<<":"<<endl;
CQ.at(i).snapshot(device);
}
}
break;
default:
cout << "No such queue; wrong option." << endl;
break;
}
}
/*moves a process from a particular CPU into a particular printer queue*/
else if(input=='p')
{
if(n>pr)
{
cout<<"You are exceding the amount of queues available for this device."<<endl;
}
else
{
/*start of push */
vector <proc> temp1;
int big;
temp1=RQ[num1-1].get_cpu();
if (temp1.empty())
{
big=get_biggest_queue_pos(RQ);
temp1=RQ[big].get_front();
temp1.at(0).change_q(num1-1);
RQ[num1-1].enter_to_rq(temp1.front());
RQ[num1-1].cpu();
}
/*end of push */
int ind=1;// to determines it's a printer when asking for parameters
vector <proc> temp;
temp=RQ[num1-1].get_cpu();
int nn=temp.at(0).get_first();//to determine if process already has parameters (if nn=1)
if(nn==0)
{
RQ[num1-1].get_info(ind);//input process parameters
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
else
{
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
RQ[num1-1].clear_cpu();
proc te(0,0,0);
te=temp.front();
PQ[n-1].enter_to_rq(te);
}
}
/*moves a process from a particular CPU into a particular disk queue*/
else if(input=='d')
{
if(n>di)
{
cout<<"You are exceding the amount of queues available for this device."<<endl;
}
else
{
/*start of push */
vector <proc> temp1;
int big;
temp1=RQ[num1-1].get_cpu();
if (temp1.empty())
{
big=get_biggest_queue_pos(RQ);
temp1=RQ[big].get_front();
temp1.at(0).change_q(num1-1);
RQ[num1-1].enter_to_rq(temp1.front());
RQ[num1-1].cpu();
}
/*end of push */
int ind=0;// to determine it's a printer when asking for parameters
vector <proc> temp;
temp=RQ[num1-1].get_cpu();
int nn=temp.at(0).get_first();//to determine if process already has parameters (if nn=1)
if(nn==0)
{
RQ[num1-1].get_info(ind);//input process parameters
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
else
{
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
RQ[num1-1].clear_cpu();
proc te(0,0,0);
te=temp.front();
DQ[n-1].enter_to_rq(te);
}
}
/*moves a process from a particular CPU into a particular cd/rw queue*/
else if(input=='c')
{
if(n>pr)
{
cout<<"You are exceding the amount of queues available for this device."<<endl;
}
else
{
/*start of push */
vector <proc> temp1;
int big;
temp1=RQ[num1-1].get_cpu();
if (temp1.empty())
{
big=get_biggest_queue_pos(RQ);
temp1=RQ[big].get_front();
temp1.at(0).change_q(num1-1);
RQ[num1-1].enter_to_rq(temp1.front());
RQ[num1-1].cpu();
}
/*end of push */
int ind=0;// to determine it's a printer when asking for parameters
vector <proc> temp;
temp=RQ[num1-1].get_cpu();
int nn=temp.at(0).get_first();//to determine if process already has parameters (if nn=1)
if(nn==0)
{
RQ[num1-1].get_info(ind);//input process parameters
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
else
{
RQ[num1-1].bur_info();
temp=RQ[num1-1].get_cpu();
}
RQ[num1-1].clear_cpu();
proc te(0,0,0);
te=temp.front();
CQ[n-1].enter_to_rq(te);
}
}
/*moves a process from a particular printer queue to it's ready queue*/
else if(num11=='P')
{
if(enter=="P")
{
cout<<"missing values"<<endl;
}
else if(inp>pr)
{
cout<<"Invalid input."<<endl;
}
else if(PQ[inp-1].tamano()==0)
{
cout<<"There are no more processes in the Queue"<<endl;
}
else
{
vector<proc> temp;
temp=PQ[inp-1].get_device();
proc te(0,0,0);
te=temp.front();
correspond=te.get_q();
RQ[correspond].enter_to_rq(te);
}
}
/*moves a process from a particular disk queue to it's ready queue*/
else if(num11=='D')
{
if(enter=="D")
{
cout<<"missing values"<<endl;
}
else if(inp>di)
{
cout<<"Invalid input."<<endl;
}
else if(DQ[inp-1].tamano()==0)
{
cout<<"There are no more processes in the Queue"<<endl;
}
else
{
vector<proc> temp;
temp=DQ[inp-1].get_device();
correspond=DQ[inp-1].queue();
proc te(0,0,0);
te=temp.front();
correspond=te.get_q();
RQ[correspond].enter_to_rq(te);
}
}
/*moves a process from a particular cr/rw queue to it's ready queue*/
else if(num11=='C')
{
if(enter=="C")
{
cout<<"missing values"<<endl;
}
else if(inp>cd)
{
cout<<"Invalid input."<<endl;
}
else if(CQ[inp-1].tamano()==0)
{
cout<<"There are no more processes in the Queue"<<endl;
}
else
{
vector<proc> temp;
temp=CQ[inp-1].get_device();
correspond=PQ[inp-1].queue();
proc te(0,0,0);
te=temp.front();
correspond=te.get_q();
RQ[correspond].enter_to_rq(te);
}
}
/*terminates program*/
else if(num11=='E' || num11=='e')
{
return 0;
}
/*Moves process from CPU to it's ready queue*/
else if(input=='T')
{
if(enter=="T")
{
cout<<"missing values"<<endl;
}
else if (num1>cpu)
{
cout<<"Invalid entry, no such CPU."<<endl;
}
else if (num1==0)
{
cout<<"Invalid entry, no such CPU."<<endl;
}
else
{
vector<proc> temp;
temp=RQ[num1-1].get_cpu();
RQ[num1-1].cpu_clear();
proc te(0,0,0);
te=temp.at(0);
RQ[num1-1].enter_to_rq(te);
RQ[num1-1].clear_cpu();
}
}
/*Kills a process determined by it's PID*/
else if(num11=='K')
{
if(enter=="K")
{
cout<<"missing values"<<endl;
}
else
{
/*Borrowed code to convert a string into an int*/
/*converts the rest of numbers into a separate string*/
int n=enter.length();
char number[n-1];
for (int j=0; j<n; j++)
{
number[j]=enter[j+1];
}
string final=number;
/*end of conversion, final= string containing PID*/
/*convert the string final into an int*/
int id;
stringstream test(final);
test>>id;
/*end of conversion, id= int containing PID*/
/*End of Borrowed code to convert a string into an int*/
if (id > PID)
{
cout<<"Invalid PID, no such process"<<endl;
}
else
{
/*Check if PID is in a Q or CPU and delete process*/
bool buscar;
buscar=get_pid_process(RQ, id);
if(buscar==false)
{
buscar=get_pid_process(PQ, id);
}
if(buscar==false)
{
buscar=get_pid_process(DQ, id);
}
if(buscar==false)
{
buscar=get_pid_process(CQ, id);
}
if(buscar==false)
{
cout<<"Process not found."<<endl;
}
}
}
}
/*If invalid input*/
else
{
cout<<"Invalid input, re-enter command."<<endl<<endl;
}
}
return 0;
}
PROCESS CONTROL BLOCK
There is a Process Control Block for each process, enclosing all the information about the process. It is a data structure, which contains the following :
Process State - It can be running, waiting etc.
Process ID and parent process ID.
CPU registers and Program Counter. Program Counter holds the address of the next instruction to be executed for that process.
CPU Scheduling information - Such as priority information and pointers to scheduling queues.
Memory Management information - Eg. page tables or segment tables.
Accounting information - user and kernel CPU time consumed, account numbers, limits, etc.
I/O Status information - Devices allocated, open file tables, etc.
to get in details concept i should suggest you to learn from here
https://coderworld109.blogspot.in/2017/12/process-control-block-pcb.html
https://coderworld109.blogspot.in/2017/12/operating-system-process-management.html