Below given code(process1) is similar to actaul scanrio. Im updating the global_data
from another application using process id of the process1.
Because of getchar()
in process1, when I run this process like,
$ ./process1 &
following message is displayed.
[1]+ Stopped (tty input) ./process1
I can't remove getchar()
. so how to run both applications.
Note: telnet/ssh options tried. If I connect though telnet, then only that telnet window is active. At max I can work through only one terminal.
#include <stdio.h>
volatile int global_data = 0;
int main()
{
FILE *fp = NULL;
int data = 0;
printf("\n Address of global_data:%x \n", &global_data);
while(1)
{
if(global_data == 0)
{
getchar();
continue;
}
else if(global_data == 2)
{
fp = fopen("JeyTest.txt", "w+");
if(fp == NULL)
{
printf("\n Error in file creation..... \n");
break;
}
for(data = 0; data < 1000; data++)
{
fprintf(fp, "%d\n", data);
}
fclose(fp);
break;
}
}
return 0;
}
Create a text file with the data you want to introduce to the process, and redirect the input:
$ ./process1 < file_with_data &
This mode avoid stopping the process because the stdin will be taken from file. The input file must have enough data to the process requeriments.