R
rohitsagar
I want to do fork from a program
Code is very simple, below is the code, it just execute a executable
called a.exe, I want to run a.exe 600 times.
#include<stdio.h>
#include<stdlib.h>
void main()
{
pid_t pid;
int i;
char *a="ls";
i=0;
for(i=0;i<600;i++)
{
pid = fork();
if(pid == 0)
{
/* Child process: */
system(a.exe);
exit(0);
}
else if(pid > 0)
{
/* Parent process: */
printf("\n I just invoked group # %d",i);
}
else
{
/* Error handling. */
printf("\n couldn't fork");
exit(1);
}
}
}
NOW THE PROBLEM, the problem is when this code ends it does not give
me prompt back.
Like the output of a.exe is (Lets says "HELLO WORLD")
The screen would look like
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD
I want it to look like
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD
Unix Prompt_>
The output is not stuck, I dont need to hit ctrl c, it is just at
prompt, but does not show. If I do ll -tr I see the contents Eg.
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD ll -tr
I tried using exit(0) , _exit(0)
but still any idea ?
Code is very simple, below is the code, it just execute a executable
called a.exe, I want to run a.exe 600 times.
#include<stdio.h>
#include<stdlib.h>
void main()
{
pid_t pid;
int i;
char *a="ls";
i=0;
for(i=0;i<600;i++)
{
pid = fork();
if(pid == 0)
{
/* Child process: */
system(a.exe);
exit(0);
}
else if(pid > 0)
{
/* Parent process: */
printf("\n I just invoked group # %d",i);
}
else
{
/* Error handling. */
printf("\n couldn't fork");
exit(1);
}
}
}
NOW THE PROBLEM, the problem is when this code ends it does not give
me prompt back.
Like the output of a.exe is (Lets says "HELLO WORLD")
The screen would look like
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD
I want it to look like
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD
Unix Prompt_>
The output is not stuck, I dont need to hit ctrl c, it is just at
prompt, but does not show. If I do ll -tr I see the contents Eg.
HELLO WORLD
HELLO WORLD
HELLO WORLD
HELLO WORLD ll -tr
I tried using exit(0) , _exit(0)
but still any idea ?