Question

In: Computer Science

You will create a number of threads—for example, 100—and each thread will request a pid, sleep...

You will create a number of threads—for example, 100—and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through the sleep() function, which is passed an integer value representing the number of seconds to sleep.

Write the program in C .

Solutions

Expert Solution

Code:

Java thread examole by extending thread class
class Multi extends Thread
{
public void run()
{
System.out.println("Thread is running....!");
}

public static void main(String args[])
{
Multi t1=new Multi();
t1.start();
}
}


//Thread example by implementing runnable interfaces
class Multi2 implements Runnable
{
public void run()
{
System.out.println("Thread is running...---");
}
public static void main(String args[])
{
Multi2 m1=new Multi2();
Thread t1=new Thread(m1);
t1.start();
}
}


// Sleep method example
class SleepMethod extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
{
try{Thread.sleep(500);}catch(InterruptedException e)
{System.out.println(e);}
System.out.print(i);
}
}
public static void main(String args[])
{
SleepMethod t1=new SleepMethod();
SleepMethod t2=new SleepMethod();
t1.start();
t2.start();
}
}
//Join method example
class Multi extends Thread
{
public void run()
{
System.out.println("Running...");
System.out.println(Thread.currentThread().getName());
}
public static void main(String args[])
{
Multi t1=new Multi();
Multi t2=new Multi();
System.out.println("Name of t1: "+t1.getName());
System.out.println("Name of t2: "+t2.getName());

System.out.println("Id of t1: "+t1.getId());
System.out.println("Id of t2: "+t2.getId());
System.out.println("Priority of t1: "+t1.getPriority());
t1.setName("Saikumar");
t1.start();
System.out.println("Name of t1 after changing: "+t1.getName());
  
}
}

Output:


Related Solutions

Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and...
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through...
Write a C code to let the main thread create N child threads, where each created...
Write a C code to let the main thread create N child threads, where each created thread will randomly generate an integer between 0 to 10 and put it into a global array variable. After that, the main thread will calculate the sum of all the generated integers. N should be input as a command line argument. Complete the following C code by filling all “???”s in the code sketch. NOTE: when you compile the code, you need to add...
You will need to provide screenshots of each number and each task. Example: Number 8 in...
You will need to provide screenshots of each number and each task. Example: Number 8 in VM One should have 20 screenshots, one for each command. Once completed merge all shots into a Word document and upload to the appropriate drobox. VM One Ubuntu 8 GB RAM 20 GB HDD (Dynamic) Install from Live DVD Run Command to Update Run Command to Upgrade Create a new file named Mid-Term and store it in the /bin directory Run 20 Terminal Commands...
General Instructions for Discussion Responses to Classmates Create a new thread for each posting. Use correct,...
General Instructions for Discussion Responses to Classmates Create a new thread for each posting. Use correct, complete sentences, in paragraph format, unless otherwise instructed. Use assigned course materials to complete discussion responses. Use in-text citations and a Reference List in APA format to cite the course resource(s) used - an in-text citation cannot exist without a corresponding Reference List, and a Reference List cannot exist without a corresponding in-text citation. Post responses here in public discussion forum. Put the following...
Create a java random program from example (1,2,3,4,5,6,7,8,9,10) But do exception for number 7 when you...
Create a java random program from example (1,2,3,4,5,6,7,8,9,10) But do exception for number 7 when you run the program first time for example it will print 3 then when you run the program for the second time it will give a random number for example 9 but number 7 will not be printed because we need you to do exception for it.
Wendy wants to estimate the mean number of hours that college students sleep each night. She...
Wendy wants to estimate the mean number of hours that college students sleep each night. She obtains a simple random sample of 41 college students and finds that the sample mean is 6.7 with a standard deviation of 1.9. Construct a 90% confidence interval to estimate the population mean and interpret your answer in a complete sentence (round numbers to 1 decimal place).
Wendy wants to estimate the mean number of hours that college students sleep each night. She...
Wendy wants to estimate the mean number of hours that college students sleep each night. She obtains a simple random sample of 41 college students and finds that the sample mean is 6.7 with a standard deviation of 1.9. Construct a 90% confidence interval to estimate the population mean and interpret your answer in a complete sentence (round numbers to 1 decimal place).
1. [100] Create a C program for a number guessing game. Here are the requirements: a....
1. [100] Create a C program for a number guessing game. Here are the requirements: a. Your program generates a random number between -100 and 100 and keeps asking the user to guess the number until the user guesses it correctly. Your random number generator should be implemented as a C function which takes min and max values as input parameters and returns a random number between those values including the min and the max. b. If the user guesses...
Your EHR has been implemented and you would like to request a number of enhancements. Pick...
Your EHR has been implemented and you would like to request a number of enhancements. Pick 1 strategic enhancement and define 3 considerations for making it a successful request. How do you make sure they are a priority for the organization?
A. Suppose you want to study the number of hours of sleep full-time undergraduate students at...
A. Suppose you want to study the number of hours of sleep full-time undergraduate students at Belmont get each evening. To do so, you obtain a list of full-time undergraduate students at Belmont, obtain a simple random sample of ten students, and ask each of them to disclose how many hours of sleep they obtained the most recent Monday. What is the population of interest in this study? What is the sample? Explain why number of hours of sleep in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT