C++ :: Give Output To Child Process

Apr 15, 2012

I'm trying to build a basic shell for Unix. This is the code I use to create a new process:

Code:
pid = fork();
if (pid == 0) {
setpgrp();
complexCommand(argv, isComplex);

[code] .....

Where complexCommand is a function that handles the command (uses execvp after generating the correct string out of argv). My problem is that after if while in the shell I use a program that needs to print to the screen and handle input, it doesn't work as expected. To test this, I built this small program:

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int x1, x2;

[code] ....

And when I use the shell I built to run it, the output is only "Enter 2 numbers" for one time. It doesn't print the result, or anything else. Is there anything I need to do in the parent process (my shell in this case) to give the child the output?

View 2 Replies


ADVERTISEMENT

C++ :: Executing A Child Process?

Oct 11, 2012

how I can run this as a separate process from the parent program, like a child process,

and return the result back to the parent program.

this script is as follows.

if file "/Stuff/s" exists then continue to run, if file "/Stuff/t" exists, then print "started" if file "/Stuff/t" does not exists, then print "stopped"

if file "/Stuff/s" does not exist then print "quit" and then quit.

Code:
void controlxmmscheck( ) {
if( access( "/Stuff/s", F_OK ) != -1 ) {
xmmscheck
} else {

[Code]....

View 1 Replies View Related

C++ :: Writing To 2D Array Of Pipes In Child Process

Apr 15, 2014

I am writing a program that is supposed to open a directory as a command line argument, read that directory, open each file and count a number of occurrences of a certain character, taken from the user as cin, fork the parent process to create a child process for each file. a pipe is created for communication with the parent and a 2 dimensional array of pipes is needed for communication with each child process (each file), one for the pipe number and the other is the read/write descriptor(0 or 1). My program is looping through all the files ok, but it seems it isn't writing the "char a" to the pipe correctly. f

For every child, do_child_stuff() is called, and it reads the file name, opens it, counts the # of occurrences and returns that count to the parent to hold a total for all the files. normally to write to a pipe, it should be write(pipe_name[1], &a, sizeof(a)) but I don't know how to do this with an array of pipes. i try to write to it by doing write(child_pipe[pc][1], &a...) pc is the array position for that pipe and it gets incremented after reading each file.

struct dirent *d;
struct stat sb;
int adult_pipe[2];
int child_pipes[1000][2];

[Code]....

View 5 Replies View Related

C :: Create 9 Child Processes And Eventually Write From Each Process To Another?

Nov 18, 2013

I want to create 9 child processes and eventually write from each process to another. How can I specifically create 9 child processes and leave them running? Right now, I am using a loop from i=0 to i=8 and running fork() within that loop, but each child process also runs the loop, which spawns dozens (maybe hundreds?) of processes. I specifically only want to create nine of them. How can I do this?

Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>

[Code].....

View 7 Replies View Related

C/C++ :: How To Give A Color To The Text That Displayed In Output Screen

Jan 27, 2013

i am using c++v30.5 version i want red color text in in my output screen . i viewed various site but the result is 0 ,wat to do?

View 2 Replies View Related

C# :: Give Image Name As Sequence Number?

Nov 18, 2014

I'm saving the images in folder by using:

webClient.DownloadFile(href, sourcepath);

I don't want to give name as Current date and time..shown in given below code

string sub = @"Gadhada";
DirectoryInfo subFolder = dir1.CreateSubdirectory(sub);
Imagename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +

[Code].....

I want to save my imagename as 1.jpg, 2.jpg, 3.jpg.

View 1 Replies View Related

C/C++ :: How To Give Validation For Character String

Aug 26, 2013

If i have character string 'char name[30]' how to give validation for the name entered by user?

View 4 Replies View Related

C Sharp :: How To Give Backcolor To The Button

Jul 14, 2014

I am designing a form ..in wich i used 3 buttons...from these 3 butons ,i wanna give backcolor to button1 . How to give it a backcolor?

View 1 Replies View Related

C/C++ :: RAM Does Not Give A Valid Preprocessing Token

May 2, 2014

#define PROJECT_ID ram  
#define QUOTES(FILENAME)  #FILENAME
#define DATA_VAR_FILENAME(PROJECT_ID) QUOTES(../##PROJECT_ID##_data_var.h)
#define DATA_VAR_FILE(PROJECT_ID) DATA_VAR_FILENAME(PROJECT_ID)
#define CUST_DATA_VAR_FILENAME DATA_VAR_FILE(PROJECT_ID)

When I tried to include CUST_DATA_VAR_FILENAME like below
#include CUST_DATA_VAR_FILENAME

Will get below error
error: pasting "/" and "ram" does not give a valid preprocessing token

View 1 Replies View Related

C Sharp :: How To Give Scroll Bar For Group Box

Oct 11, 2012

Is there any methods to add scroll bar for group box

My code scenerio is: I have many groupbox in form, all group box will be appears in same place and also height and width is fixed. I'm doing group box visible true/false according to condition.

So some groupbox ecxeeds the width and heighto so I want to put this all in scroll Bar

View 2 Replies View Related

C++ :: How To Give Database Connection To Code

Apr 11, 2013

how to give a database connection to a c++ code i am using turbo c++ as an editor and if i have oracle 11g client, odbc as a driver , what else i require and how to link these things in a code.

View 1 Replies View Related

C++ :: Add And Minus From Text File Not Give Right Value

Feb 5, 2014

I'm creating a bank system.

So I know to make a deposit to the balance, which add ups what is the balance to i have add.

When i run the deposit function, its work well in some ways. If balance(text file) has the value 10, add i addSum 20, the balance will become 30, same as the text file will become 30. so its work well to add positive number.

Code:
double deposit(double balance) {
double addSum = 0;
system("CLS");
cout<< "Welcome to deposit."<<endl;
cout<<"Enter a sum you wish to add to your account:";

[code]...

When I withdraw from 30 which is the balance, then i takeSum, for example i take away 30. The balance will become 30 - 30 = 0 When i make another withdraw from example -150, it will be -150.Which shows correct.

But when i make a deposit from -150 and i addSum 130, the balance shows -500, and it should had been -20.

Code:
double withdraw(double balance) {
double takeSum = 0;
system("CLS");
cout<< "Welcome to withdraw."<<endl;
cout<<"Enter a sum you wish to take away from your account:";

[code]...

View 2 Replies View Related

C++ :: Find X And Y Groups Integers And When Added Give Sum Of Z

Jan 26, 2013

You are given 3 integers x,y,z. you must find all groups of x integers until y, that when added give a sum of z.

View 2 Replies View Related

C++ :: How To Give Fraction Object In S String Via Template

May 9, 2014

I am trying to give fraction object in s string via template.

struct Fr // simple Fraction {
int num;
int denom;
Fr(int i,int j) {

[Code] ....

View 10 Replies View Related

C++ :: XML File - ReadFile Function Does Not Give Right Values

Aug 21, 2014

I am trying to read this xml file. This readFile function does not give me right values. Only to use cstring..no pointers or other libs such as xml libs

void readFile(char file[], ifstream& read){
char line[chr_len];
read.open(file, ios::in);

if(read.fail())
cout<<"Sorry could not read";

[Code] ....

Also how can i only read the values..not the tags?

View 8 Replies View Related

C++ :: Don't Give Correct Location Of Max / Min Number In Array

Nov 8, 2013

All my code is good, except the functions: findMacLoc and findMinLoc .They don't give me the correct array location of the max/min number in the array.I know is something simple I need to tweak in those two functions.

#include <iostream>
#include <time.h>
using namespace std;
void printArray(int a [], int & size)
{
int i;
for (i = 0; i < size; i++)
cout << a[i] << " ";

[code].....

View 2 Replies View Related

C++ :: Program That Will Give Multiple Calculation Results

Apr 4, 2013

I need to write a program that will give me multiple calculation results.

#include <iostream>
using namespace std;
int main () {
int x = 8;
int y = 7;

[Code] ....

It only calculates the last two numbers: 1 and 0, so therefor it gives me 1.

But i need to calculate x and y each time they are smaller(incremented) by one digit.

Please note that the int calculation formula needs to stay.

View 2 Replies View Related

C/C++ :: Program To Take A Number From The User And Give Reduced Sum

Dec 30, 2014

i have only recently got into programming. i have this homework assignment that is frying my brains, the program needs to take a number from the user and give the 'reduced' sum. for example: if the user enters 888 then the sum should be: 6. it takes the number and adds its digits im just looking for a direction to where my problem is

#include "iostream.h"
int reduction (int number) {
return number/10+number%10;
}
int main() {
int number,loopcount;
cout<< "please enter a number"<<endl;
cin>>number;

[Code]...

View 2 Replies View Related

C/C++ :: 2D Dynamic Arrays - How To Create And Give Values

Apr 23, 2014

I cant get with part of it is wrong, i want to sum every row, too.

// Color Number.cpp : Defines the entry point for the console application.
//  
#include "stdafx.h"
#include<conio.h>
#include<iostream>

[Code].....

View 1 Replies View Related

C Sharp :: Can Give The Restriction To Method For A Particular Class

Jun 16, 2012

can we give the restriction to method for a particular class

View 1 Replies View Related

C# :: How To Add A Child Row To A Table

Aug 1, 2014

I have a table in which data is populated via an element. However some elements can have a parent element

The client now wants all the children and parent elements to be next to each other row wise.

How can i add the child rows under the parent rows?

parents
foreach (var inspection in elemInspections) {
var date = db.INSPEVNT.Find(db.INSPEVNT.INSPKEY == inspection.INSPKEY && db.INSPEVNT.BRKEY == m_sBrKey);
var paircode = db.PON_ELEM_DEFS.Find(db.PON_ELEM_DEFS.ELEM_KEY == inspection.ELEM_KEY);

[Code] .....

how can i make it so the children go under the parent rows?

View 2 Replies View Related

C :: Give Error Message If User Inputs Wrong

Nov 2, 2013

Code:

#include<stdio.h>
void main
{
int i;
int marks[10];
}

[code]....

how to give error and ask user to re enter if user enter other then a number?

View 6 Replies View Related

C++ :: Give Appropriate Color Code For Resistor After User Input

Sep 18, 2013

I am in the process of writing a program that will give the appropriate color code for a resistor after the user enters an integer value for the resistance needed and selects the tolerance form a list. My question is this: Is there a way to allow the user to enter a value such as 75000 and C++ use each digit separately, as if they entered 7 [enter], 5[enter], 0 [eneter]... and so on? But, then use the entire value as an integer too? Also, it should read a value such as: 45835, as 45000, or 1843 as 1800.

View 1 Replies View Related

C/C++ :: Exponents Solution Do Not Give Right Answer If Last Number Ends In 5

Mar 19, 2014

I have two unassigned variables A,B . My program goes as follows

#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>  
using namespace std;    
bool die (const string & msg);  

[Code] ....

This a program that makes a calculator in which this is a small portion of it, all the exponent numbers work exceptfor anything ending in 5.

Examples go as follow 2^3=8, 3^2=9, 5^2=24

I want to why this happens, is it because they are unassigned variables?

View 1 Replies View Related

C :: Pipes Between Child Processes

May 5, 2014

I wrote a C program that is supposed to create a certain number of child processes, each child process having to change 1 letter from a string. The string and the number of child processes are read from the keyboard. I want to do it using pipes.

It should work like this: The parent changes one letter, then the first child takes the string modified by the parent and changes one more letter. The second child takes the string modified by the first one (2 letters are already changed) and changes one more and so on. I am new to C and am not quite sure how it all works, especially pipes. Also can the children be linked between them through the pipe, or can they only be linked to the parent and it has to be something like: first child changes a letter, gives the string back to the parent and then the second child reads from there, modifies letter and gives back.

If it's like that, is there any way to make sure that this doesn't happen: Apples becomes AppleD and then AppleX and then AppleQ? For example:

Code:
Input: Apples
Output: Applex Appldx Aqpldx My problem is: I don't get any output from the children.

Here's my code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include <sys/wait.h>

[Code] .....

View 2 Replies View Related

C++ :: Program Compiles Successfully But Calculations Give Wrong Answer

Feb 11, 2013

I'm using MSVC++ and it builds sucessfully but somewhere something is obviously messed it. Once i try to debug it just shows weird numbers.

int k=0; //could this be the problem??? since 0 would be over writing any given value. but if i leave int k; it showsa warning and MSVC would count that as an error

#include "stdafx.h" //Header file section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//structure declaration
struct menuitemtype

[Code] ......

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved