C :: Making Fork Call And Have The Instances Run Every Five Minutes
Dec 18, 2014
Understanding Fork() calls. I have to write a C program in UNIX machine, and make two Fork Calls Inside it and have these two instances run every five minutes all round the clock. How to achieve this.
View 1 Replies
ADVERTISEMENT
Mar 28, 2014
look at this code:
#include <iostream>
using namespace std;
class teste
[Code]....
Each time i call "x = new teste();" the previous object is deleted? Does this code cause any sort of memory leak?
View 1 Replies
View Related
Apr 15, 2014
when to use fork and vfork? I am using execl in my child. which one I need to use?
View 1 Replies
View Related
Sep 26, 2014
what I'm trying to do is create 3 child processes stemming from one parent process. I have figured that out but the problem is my program exits when it get to the third child leaving it orphaned(I think).
This is my code for the first generation of processes:
int i = 0;
pid_t child;
about("Dad");
printf("Now .. Forking !!
[Code] .....
I have created a menu GUI that I feel messes with the loop commands, i.e. "Continue". The menu pops up repeatedly after each child process is created. I commented out the block of code for menu which fixed it. I was wondering if there is a way so that I can have the menu not messing with the processing?
View 1 Replies
View Related
Dec 23, 2012
How can I implement the paradigm demonstrated by the code below to run on WinXP?
I want to fork a process or create a thread that shares global variables with the parent process/thread.
The child process/thread monitors the progress of the parent process/thread.
I cannot find documentation for a fork function per se, a Unix term. It might be called something different for WinXP.
I would be happy to use threads instead. But I'm rusty even with Unix application threads; and I know nothing of WinXP application threads.
So any turnkey implementation that demonstrates the simplest use of process or thread functions for my purpose demonstrated below.
In either case, do "forked" processes and threads share global address space in WinXP, as they do in Unix?
I would prefer to avoid the overhead of IPC mechanisms. The "overhead" includes my own relearning curve.
The GUI screwed up my indentation. I would try to correct it. But the proper indentation appears when I edit the posting. I suppose I need to insert real tabs. Haven't figured out how (yet).
Not even real tabs work; and I cannot get the "paste as text" button to behave as I expect. What is the trick for posting indented text in this GUI?
#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
long curCount;
int isRunning;
int _tmain(int argc, char* argv[]) {
curCount = 0;
isRunning = 1;
[code]....
View 4 Replies
View Related
Aug 8, 2013
I am currently trying to write a code that will store PID numbers of a child after a fork, I have to be able to enter an amount that will be created, so far I have managed to be able to get them to print (which puts me on the right path as far as I am concerned) but I am having issues. Using the following code:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
[Code].....
View 3 Replies
View Related
Apr 19, 2014
I am reading up on the clock() function: URL....It states: "On a 32bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approximately every 72 minutes."
How could this return the same value, if clock is the number of clock ticks elapsed since program execution. Wouldn't the number of clock ticks continue to grow, and as such, when we divide by 1000000, the return value should continue to grow. So how does this function return same value every 72 minutes?
View 2 Replies
View Related
Oct 23, 2014
I am currently working on a lab for my intro to programming class and the lab is asking for a long distance call calculator. Based on the times that you start your rate will change. If the call starts from 00:00 to 07:59, Rate = $0.07. If the call starts from 08:00 to 18.59, Rate = $0.12. Lastly if the call starts from 19:00 to 23:59, your rate is $0.28.
Then on the output you must show the start time, end time, rate, and total cost of the call.
My confusion is on the end part of the code (the output).
I know you have to use the % operator to convert minutes to hours, but I don't completely understand it which is why I am here. How does the modulus do that? And how will it go over to the next hour if the call starts at 1:35 and ends after 30 minutes (2:05)?
Here is what I have so far.
#include <iostream>
#include <string>
using namespace std;
int main() {
float callStart, minutes;
double cost;
char choice('Y');
string rate;
[Code] ....
View 5 Replies
View Related
Sep 1, 2014
I have a function which sometime takes more than 24 hours to run. So I want a code which will check the time and exit the function if the function executin is not successful and return to main function.
View 9 Replies
View Related
Apr 7, 2014
I want to add a count down timer to my testing software 1hr and 30min
Its a 32bit console application, I want the countdown timer outputted above each question on the right side, timer only needs to output the time left at the top of each question so a live outputted timer is not important.
Questions are not random generated.
Also how to output "out of time" if the timer reaches 0 and for the test to end, I think branching is involved not too sure.
I already have, std::srand( std::time(0) ) ; at the start of the test to randomly generate the answer order.
View 10 Replies
View Related
Mar 13, 2013
I am looking for a function or any example that shows elapsed time in seconds and minutes. I didn't find any solution for both OS Win and Linux. I am looking for example that works for both - win and linux.
View 14 Replies
View Related
Oct 22, 2013
I have to write a program for class in which users will be inputting:
start time = startTime
number of minutes = callDuration
so first off, teacher wants us to input time as a floating point number such as 09.00
How do I validate the time so that users cant input i.e. 09.61 for every hour? In other words, so the user cant input minutes 60-99 for every hour.
then, when calculating:
endTime = startTime + callDuration
how would I make endTime display a correct time in such a situation: endTime = 09.45 + 00.30
so that it displays 10.15 not 09.75
View 4 Replies
View Related
Nov 29, 2014
Design, implement, and test a class that represents an amount of time in minutes and seconds. The class should provide a constructor that sets the time to a specified number of minutes and seconds. The default constructor should create an object for a time of zero minutes and zero seconds. The class should provide observers that return the minutes and the seconds separately, and an observer that returns the total time in seconds (minutes x 60 + seconds). Boolean comparison observers should be provided that test whether two times are equal, one time is greater than the other, or one time is less than the other. (You may use RelationType and function ComparedTo if you choose). A function should be provided that adds one time to another, and another function that subtracts one time from another. The class should not allow negative times (subtraction of more time than is currently stored should result in a time of 0:00). This class should be immutable.
this is one of my main errors: Error1error C2653: 'Time' : is not a class or namespace namec:userskdesktop
oane statecisp 1610visual studioschapter 12 assignmentchapter 12 assignmentchapter 12 assignment.cpp131Chapter 12 Assignment
//The implementation file ImplFileTimeClassAsgnt.cpp:
#include "Time.h"
#include <iostream>
using namespace std;
Time::Time() {
mins = 0;
secs = 0;
[Code] ....
View 2 Replies
View Related
May 28, 2013
So I am wondering how I would go about calling a function for all instances of an object. I tried googling it, but all I saw was solutions like making an array of pointers to the objects. What if I don't know how many objects there will be? Isn't there an easier way?
View 19 Replies
View Related
Jul 24, 2014
The problem is that I need to figure out the user's birthday in months, days, hours, and minutes from today's date.
Here's what I have so far.
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
int main() {
int todayDay, todayMonth, todayYear;
int birthDay, birthMonth, birthYear;
[Code] ....
I haven't initialized all the variables, yet. And it's very unfinished. I need to figure out how to convert years from the age into months only. And I need to figure out how to calculate the hours, seconds, and minutes.
View 3 Replies
View Related
Feb 1, 2015
I am struggling to understand what the correct way to initialize instances of a class for object orient programming is.
If I am not mistaken, there are 2 methods to initialize an instance "instance_name" of CLASS1 by calling the constructor:
(1) CLASS1 instance_name(argument);
(2) CLASS1 instance_name=CLASS1(argument);
As it turns out, I cannot use method (1) when I try to initialize a private instance inside another class. But I can use it in the main() code. I hope the code below will explain what I mean. Why only method (2) will work inside another class? Or is there another fundamental mistake I am making?
(BTW: I used CodeBlocks 13.12 with GNU GCC compiler for this example)
#include <iostream>
using namespace std;
class CLASS1{
[Code].....
View 6 Replies
View Related
Sep 3, 2013
template <typename T> struct avl_tree {
T data;
int balance;
struct avl_tree <T> *Link[2];
static int (*comp)(T, T);
};
In main, I have a function like so:
int compare(int a, int b) {
return ( a - b );
}
Now how do I assign the function pointer in my avl_tree class to the compare function?
I did this:
int (avl_tree<int>::*comp)(int, int) = compare;
But I got the compiler error:
Tree_Test.cc: In function ‘int main()’:
Tree_Test.cc:27:42: error: cannot convert ‘int (*)(int, int)’ to
‘int (avl_tree<int>::*)(int, int)’ in initialization
View 12 Replies
View Related
Mar 29, 2015
Code:
#include<iostream>
#include<conio.h>
#include<string.h>
#include<ostream>
#include<fstream>
#include<iomanip>
using namespace std;
class MathProblem {
[Code] ...
So my program is quite simple, have the user answer the answer to a question, and then compare with the correct answer. I needed to implement an inheritance of MathProblem in my second class aswell.
The program runs as I intend but I wish to have the data forwarded to a text file. After that I must read back to the command prompt the text file contents. It's fairly easy for simple statements but I don't understand how to forward all my data from my classes.
View 3 Replies
View Related
Mar 24, 2012
I'm trying to search a specified file for all instances of substring "abbaa."
The professor is making us use a 6x3 array in order to understand finite state machines.
Well the code I wrote runs perfectly, but the case for '/n' doesn't catch. It just flows through without it.
Significant portion of code:
Code:
if(fin) {
fin >> inChar;
while(fin) {
switch(inChar) {
case 'a':
currentState = state[currentState][a];
[Code] .....
View 3 Replies
View Related
Jun 17, 2012
i have this rather large class, which (in a way) somehow resembles a custom dialog control). This control is supposed to display data, which it does just fine. To do so, it maintains a
byte settings[10];
array, which holds information on how to display the data.
There are multiple ways to represent this custom set of data.In order to remain flexible in representing it, i thought of implementing some sort of DisplayProvider, which can be registered to the base class and provides that settings byte array.
Preferably, i would now have a set of static const instances of this provider.Using a struct would work nicely here:
PHP Code:
struct DisplayProvider
{
int settings[10];
}
static const DisplayProvider prov1 = {1,2,3,4,5,6,7,8,9,0};
The problem: The DisplayProvider would have to do some pre-processing, before handing over control to the base class, which then does the main work.I would end up with something like this:
PHP Code:
class DispalyProvider
{
baseclass* owner;
int settings[10];
void PreProcessing(...);//ends up calling the owner.Processing(...) function
};
The main thing here is, that i dont really see a way to create a stock of default "static const DisplayProvder = {...}"s, as i could when using a struct.
View 7 Replies
View Related
Oct 4, 2012
is it possible to have a global variable pointing to a different address depending on the thread?
Imagine one would like to use threads with the loop:
for (i=0;i<n;i++){
globalPointerVariable=getAddress(i);
DoThingsUsingThe_globalPointerVariable();
}
View 4 Replies
View Related
Mar 31, 2013
Here is what I have going on.
Code:
struct client {
char firstName[stnd];
char lastName[stnd];
long ID;
char email[stnd];
float funds;
float wager;
}
typedef client...I would like to have these fields filled with this function below and stored in an array... Basically Multiple users and this is my function for it, if I can get it to work proper -.- .... I don't get syntax errors but I do get warnings
Code:
void getct(client *cl, int *pclientCounter) {
char input[buff];
char *pinput = NULL;
int typef = 0;
int lengthf = 0;
}
[code]....
View 3 Replies
View Related
Feb 10, 2015
Using SFML, I had a Board class which held multiple vectors of all of my object types in the game, and then it also held a vector of pointers to the memory addresses of these object instances, like this
class Board{
//...
std::vector<AbstractObject*> GetAllLevelObjects(){ return allLevelObjects; }
//so these are used to hold my object instances for each level
[Code]....
When looping through this vector and drawing the sprites of the objects, I get the runtime error 0xC0000005: Access violation reading location 0x00277000. I solved this error by storing the vector of pointers in the class that holds my Board instance, but I'm wondering why only this solution worked? Why couldn't I just have my vector of pointers in the same class that the instances of those objects were in?
View 2 Replies
View Related
Nov 10, 2014
I am trying to do some exercises but am struggling at the moment. The first task was to create a class (Planet), then allow the user to edit their entry or view it.
The second one is to create class instances from a text file. The file contains a new planet on each line in the form: 'id x y z' where x/y/z are its coordinates. As the file can have more then one lines, it has to dynamically create an undefined amount of class instances.
To do this I used 'new' and it works ok - it prints each one out to the screen as you go so you can see it working. However... I'm trying to get into good habits here and am encapsulating the class which is where I am getting stuck. I can read from the class but cannot put the values from the file into the class.. ..using the member functions I have created anyway.
My code so far is:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Planet {
private:
int id=0;
float x_coord=0.0, y_coord=0.0, z_coord=0.0;
public:
int GetID(){return id;}
[code]....
If I change the SetID etc to just p->id, p->x_coord etc it works fine. But I'd rather find a way to do it that keeps the encapsulation. Using p->z_coord etc requires that you change the class variables from private to public.
The question I have been given is this:
Define and implement a function, generate planet, that takes a stream argument that has already been connected to a file (i.e. the argument is istream& fin). The function must create a new instance of planet using new and read its details from the next line in the file.Each line of the file is in the format id x y z.The function must return the newly created planet.
Also, how would you go about 'viewing' one specific class instance once they've been created? So say the file had 5 lines, line three was '4 6 2 6'. How would I go about viewing that planet afterwards? I don't think thats required but... I'm just wondering Although I'm also wondering, are we actually creating a new class instance for each line here? Or just destroying the previous one?
View 14 Replies
View Related
Jun 23, 2014
I am getting an error with my while loop(feels dumb) when running this code that I am allowed to modify. It is to remove all instances of an element within the list.
The loop is whithin this function:
void arrayListType<elemType>::removeAll(int location)
I have attached both the header file and main function file in .txt format.
void arrayListType<elemType>::removeAll(int location)*
Attached File(s) :
header.txt (12.23K)
main function.txt (2.95K)
View 2 Replies
View Related
Sep 18, 2013
I am trying to compile a c program for sudoku. I have declare const instances as global variables, but when i try to compile the code it says that my declarations are not constant, here is some of the code.
#include <stdio.h>
#include <assert.h>
const int GRIDSIZE = 3;
const int GRID_SQUARED = GRIDSIZE * GRIDSIZE; //this line
const int ALL_VALUES = (1<<GRID_SQUARED)-1; //and this give//the error
int board [GRID_SQUARED][GRID_SQUARED];
View 3 Replies
View Related