Say i have an

int c =8;

and i want to do a fork to say do a printf

printf("hello im number blah blah");

is there a way to do that printf as many times as whatever c is equal too?
using a fork().

maybe something like

int pid;
pid=fork(c)
printf("hello im number blah blah");

Recommended Answers

All 4 Replies

Here's a very simple example:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char**argv)
{
	int i = 0;
	for (i = 0; i < 5; ++i)
	{
		if (fork())
		{
	
		}
		else
		{
			fputs("Hello, World!\n", stdout);
			exit(EXIT_SUCCESS);	
		}
	}
	exit(EXIT_SUCCESS);
}

Like using a for loop perhaps?

I dont think i for loop would do it.

from what i wrote above i would want to printf the quoute the number of times c is equal to, so 8 times. im not aware i can do a for loop for this???

unlesssss
i do a

int c = 8;
int i = 0;

while( i <= c)
{
printf("kdjfjfjfkf");
i++;
}

that would work wouldnt it ??

that would work wouldnt it ??

Yes that wouldn't work, wouldn't it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.