C/C++ :: Fork Function Involving For Loop?
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
ADVERTISEMENT
May 16, 2014
So basically it consists of implementing a single turn for the game called 'pig' and printing out scores and probabilities of those scores. So this is what I have thus far :
int randomNum (int min, int max) {
return min + rand () % (max - min + 1);
} int singleTurn (int holdValue) {
int totalRoll = 0;
int score = 0;
do {
score = randomNum(1,6);
[code]....
View 13 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
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
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
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
Dec 9, 2014
Write following functions
makingArray: this function will return a double pointer which points to a double array and take one parameter- an integer variable which has a default argument of 5. The argument is the size of the integer array. when the function is called, the users input or default argument will be used for the size of the array. The function will initialize all elements of the array with the 'cin' object.
getTotal: this function will return a double and take two parameters- a double array, which can NOT be modified by this function, and an integer variable for a size of the array. This function will calculate the total of all elements then return a double number which is the total.
main: demonstrate functions( makingArray and getTotal) by calling them in a program
View 1 Replies
View Related
Jan 30, 2014
I am currently trying to write a test program involving constructors. I know what I am about to ask is pretty basic stuff but Visual Studio is not recognizing when I declare strings for some reason. My code isn't completed yet but as I am typing string in to declare the variable in the class Visual Studio is not recognizing string as a usable value.
Code below:
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class college {
[Code] .....
Like I said... this is completely unfinished I just need to understand why my strings aren't being recognized.
View 2 Replies
View Related
May 12, 2013
I've written a c++ program that contains the following classes: class Shape, Circle, Ellipse, Rectangle, Triangle. All the classes are a subclass of class Shape. They syntax of their definition is fine, I see no visible errors. This is the code:
#include "graphics.h"
//#include <iostream>
using namespace std;
const float Pi = 3.141;
float distance (int x1, int y1, int x2, int y2) {
[Code] ....
Now when I declare a variable of each subclass in the main, I get an error on two of the classes.
int main () {
Circle a;
Rectangle b;
Ellipse d;
Triangle c;
int x1, y1;
float length;
[Code] .....
...And there's a bunch of similar if conditions. My compiler gives an error under b and d, i.e. the Rectangle object and the Ellipse object. The error is, "Expected a ';'" . I have quadruple checked every inch of my code and as far as I can tell, there are no missing semicolons. Where this ";" belongs ....
View 2 Replies
View Related
Oct 13, 2014
We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.
View 11 Replies
View Related
Dec 22, 2014
I want to store all the result which are basically 8 points generated after every time function GenTestPoint is called.
how to store all the points generated i.e 4096+512+64+8 points. However, I mainly need the 4096 points which are generated at the end. I am new to programming, not much familiar with pointer and all stuff.
Its start from level 1.
Level 1 = 8 Points;
Level 2 = 64 points;
Level 3 = 512 Points;
Level 4 = 4096 points;
8 points will be calculated only when if statement is true. But it's fine in the worst case all the statements are true and at the end we will get 4096 points. Just consider that all the if statements are true and I am getting 4096 points at the end which I need to store in some GLOBAL Variable.
I need this 4096 points at the end.
void GenTestPoint(Vec3f test, float level) {
float new_denominator = pow(2.0f,level);
Vec3f result1, result2, result3, result4, result5, result6, result7, result8;
Vec3f result11, result12, result13, result14, result15, result16, result17, result18;
result1 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);
[code].....
View 2 Replies
View Related
Nov 8, 2013
Is there a way to end a loop ?
Code:
while ( menuopt == 1)
{
printf("Lets start
");
printf("12 x 4 = ?
");
[Code] ....
View 2 Replies
View Related
Apr 27, 2015
"Write a program to gauge the rate of inflation for the past year. The program asks for the price of an item (such as a hot dog or a 1-carat diamond) both one year ago and today. It estimates the inflation rate as the difference in price divided by the year-ago price. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the rate of inflation. The inflation rate should be a value of type double giving the rate as a percent, for example 5.3 for 5.3 percent.
Your program must use a function to compute the rate of inflation. A program which does not use a function will be awarded a score of zero, even if all tests pass."
So far I've got the code below. It runs, but it outputs zero for the inflation (no matter how values I enter for the prices) and does not stop running when I enter zero.
#include <cstdio>
#include <iostream>
#include<cmath>
[Code].....
View 3 Replies
View Related
Jan 9, 2015
I'm trying to loop a function in C++/CLI but it freezes my GUI and i can't do anything anymore when this happens. Here is the part of it;
DWORD Conqq = 0x0053A124;
void ConqqFunction(bool fEnable) {
if(fEnable) {
while(1) {
for( ; ; ) {
WriteMemory(Conqq, 1, 0xD2);
[Code] ....
It freezes after i activate this function with checking the checkbox. How can i resolve this? I don't want the GUI to freeze.
View 6 Replies
View Related
Jan 14, 2015
I need this break in my main function, but I'm not allowed to put it in void since void is not located in a loop. How can I solve this?
Code:
#include <iostream>#include <string>
using namespace std;
void login(string x, string y);
string username;
string password;
string x;
string y;
[Code] ....
View 6 Replies
View Related
Oct 11, 2014
I am writing another program and I cannot find for the life of me how to loop the program back to the start of a function.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int choice;
char band1, band2, band3, band4;
printf ("This program calculates the resistor value based on the colours of the wire.
(enter the integer near the command)
");
printf ("What would you like to do?
[Code].....
This is my current iteration of the program. Obviously, I haven't finished writing the case 1 of the first switch, but for the other ones. I thought that return main would cause the program to loop back to the beginning after executing the case, but I see that it is not the case (pun not intended). Anyways, what would I have to insert to cause the program to loop again (other than for case 3)? And another question, why is it that in scanf in the first case, the program only accepts two characters before finishing?
View 4 Replies
View Related
Jun 10, 2013
I am working on a problem that requires a nest for loop to be converted to a recursive function. I am going to provide just the code instead of the entire program.
Code:
for (R1=1; R1 <+3, R1++){ //for loop
printf (something);
}
// the recursive function
void loopR1 (int R1, int max){
if (R1 <= max){
printf (something);
[Code]...
when calling the recursive function in main i am using the following statement...
loop r1(1,3)
View 4 Replies
View Related
Apr 29, 2013
How can loop this function so it keeps asking the user till they enter a correct letter that can be found in the unscrambled array?
Code:
char LetterGuessed(char unscrambled[]) {
char c;
printf("+-----------------------------+
");
printf("| Please guess a letter: |
[Code] .....
View 1 Replies
View Related
May 29, 2014
Suppose I have the following function containing while loop:
#include <iostream>
using namespace std;
int Loop () {
[Code]....
here in above code I want to return value of 'a' by calling function 'Loop'. Is there any way to do this??
for above code output should be:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
View 8 Replies
View Related
Dec 13, 2014
I am trying to convert a recursive function to a loop. However, it is not working.
//recursive function
int function(int x){
if (x % 3 == 0){
[Code]....
View 1 Replies
View Related
May 15, 2013
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){
... // some local value definition
for(int i = 0; i < 1000; i++){
... // a lot of calculations done here
return i; // -> return the value after each loop is done
}
}
Here it only returns one value, i = 0. Clearly it's wrong.
View 10 Replies
View Related
Mar 5, 2014
I have simple LCd_call function . I am calling this function from main . I wanted to call this function once. problem i am facing here, When lcd_call function being called. It enter the cases but instead of staying paricular case it coming back and starting case 1 iteslf . for every 6s it change the case to 1:
View 2 Replies
View Related
Oct 15, 2014
I have written the code below that allows the user to input any sided dice and any number of rolls. The program will print out the output in sequence. I need to sum these outputs into one number, but I am having trouble writing a sum function for this.
//This Program Creates the Sum of a Number of Dice Rolls of the Same Size
#include <stdio.h>
#include <math.h>
#include <time.h>
int rolldie();
int main(){
int x, n, a; //'x' n=number of rolls, a=number sided dice
[Code] ....
The output looks something like this currently:
Please Enter the Number Sided Dice Followed by the number of Rolls... 12 10
4 12 2 10 12 5 5 12 12 5 >Exit code: 0
View 2 Replies
View Related
Apr 18, 2013
I am having a problem with a program. I have a bunch of classes all derived from the same base class. I want to loop through a vector of objects, calling a function in each. The problem is that it doesn't matter which class the objects are, only the function defined in the base class is called.
I simplified the code as far as possible to replicate the problem. As you see, I would like a mix of numbers 1,2,3 as the output, however using the vector the only number output is 1. Here is a copy of the output by the way:
base->num() : 1
a->num() : 2
b->num() : 3
(*it)->num() : 1
(*it)->num() : 1
(*it)->num() : 1
I suspect this is the "slice" problem, because the vector is defined with pointers to the base class so it uses the base class functions? The question is how to get around it? How can I loop through a vector of objects sharing the same base class but calling each by their correct member functions?
Code:
#include <iostream>
#include <vector>
class Base {
public:
int num() { return 1;}
[Code] .....
View 5 Replies
View Related
Aug 18, 2014
I have a for loop, and after this loop, I am calling another function that wakes a thread S, and then thread S carries on its execution.
Code:
for (k = 0; k < num_msg; k++) {
if( (c % Messages[k][2] ) == 0 ) {
printf("
%d, act, %d
[Code]....
I am getting an anomalous output. Before all the iterations of for loop could finish, the program enters into the invoke_thread_S() and I can see the remaining iterations of for loop happening after thread S is finished.
What could be the problem here. Can I put a 'sleep' before I enter into invoke_thread_S() function, I tried it with a very small amount (in nano seconds), but that did not solve the problem.
View 8 Replies
View Related
Sep 23, 2014
The first problem i'm having is in the following code.
Code: #include<stdio.h>
#include<stdlib.h>
#include<time.h>
// program ask for max value and always returns random numbers < max
[Code].....
The ultimate goal of these two programs is to merge them and make one program that takes a max value from the user and fills up an array of (10^6) elements with values ranging from (0 to maxValue).
View 7 Replies
View Related