how to create a chain of processes using fork()? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create 10 processes but not fanned out but rather in a chain. So process 1 is

This is untested:
for( int generation = 0 ; generation < 10 ; ++generation )
{
int pid = fork();
if( pid != 0 )
{
// Do parental things, including wait
break;
}
// Do childish things before forking.
}
Each child knows its own generation.

Related

C++ Condition to check for lower number with a treshold [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
There surely has to be a better way to do this in C++ that this ?
if ( width_value < tipWidth )
{
if (tipWidth < threshold)
{
return threshold;
}
return tipWidth;
}
return width_value ;
return std::max(width_value, std::max(tipWidth, threshold))
Or since C++11:
return std::max({width_value, tipWidth, threshold})
That's assuming you #include <algorithm> and the type of width_value, tipWidth, threshold is the same. If not the same, you have to specify it explicitly, e.g. std::max<int>(...)

how void function can be return value? c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I do not understand, how void* function can be with return value. Code below, its work.
void *TcpClient::receive(int size=512)
{
char *buffer = new char[size];
if (recv(_sockfd , buffer , sizeof(buffer) , 0) < 0)
{
std::cerr << "recv failed";
}
return buffer;
}
The function returns void*, i.e. the pointer to memory, not void.

C++: Algorithm wrong output ( works on java ) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can someone help me with my code ? I'm trying to use different algorithm but it returns way to big numbers, when i use algorithm between /* */ it works perfect, anyone can see whats wrong with my new code ? (same on java works)
int* czynnikiPierwsze(int n)throw (string){
if(n<0){
string wyjatek1="Nie mozna rozlozyc ujemnej liczby";
throw wyjatek1;
}
int b=0;
while(n>2){
n=n/tab[n-2];
b++;
}
dzielniki=new int[b]();
int j=0;
while(n>2){
dzielniki[j]=tab[n-2];
n=n/tab[n-2];
j++;
}
/* int a=n;
int*dzielniki=new int[30]();
for(int j=0;j<n+a;j++){
while(n>2){
dzielniki[j]=tab[n-2];
n=n/tab[n-2];
break;
}
}*/
return dzielniki;
}
There's no chance your second while(n>2) loop runs even once, since the first loop only exited when that same condition was no longer true.

Checking user input in Link List (C++) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a link list here to check for user input to see whether user has input the word before or not.
ListNode *cur = head;
while ( cur != NULL )
{
if ( guess == cur->item )
{
return true;
}
cur = cur->next;
}
return false;
My problem is that even though the list is empty, it'll still enter the while loop. What's my mistake?
Do you initialize the empty list with head=NULL;? Otherwise head will most likely point to some random memory, and it will be impossible to detect that the list is empty.

Threshoding image between certain range [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to Threshold image between certain range?
i have done this but it doesn't work.
for (int i=0;i<s.size().height;i++)
{
for(int j=0;j<s.size().width;j++)
{
int k=int (s.at<uchar>(j,i));
if (k>6 && k<10)
k=255;
else k=0;
s.at<uchar>(j,i)=k;
}
}
You get an uchar value, and convert it to integer. Try this :
uchar k= s.at<uchar>(j,i);
if (k>6 && k<10) {
k=255;
}else {
k=0;
}
s.at<uchar>(j,i)=k;
I think it may work.