VirtualBox ubuntu.
I have a program that read input from trminal and output it.
c code:
#include <stdio.h>
#include <unistd.h>
int main() {
char input[256]; // Assuming a maximum line length of 255 characters
pid_t pid = getpid();
printf("My PID is %d\n", pid);
while(1){
printf("input:");
if (fgets(input, sizeof(input), stdin) != NULL) {
printf("\toutput:%s\n", input);
}
//sleep(1);
}
return 0;
}
x@ub22:~/tmp$ ./a.out
My PID is 189425
input:123
output:123
input:abc
output:abc
now from another terminal, I do
echo "123" > /proc/189425/fd/0
./a.out got the 123, but did not output it.
input:123
please help me to understand why.
thank you in advance.
Xian
I have a program that read input from trminal and output it.
c code:
#include <stdio.h>
#include <unistd.h>
int main() {
char input[256]; // Assuming a maximum line length of 255 characters
pid_t pid = getpid();
printf("My PID is %d\n", pid);
while(1){
printf("input:");
if (fgets(input, sizeof(input), stdin) != NULL) {
printf("\toutput:%s\n", input);
}
//sleep(1);
}
return 0;
}
x@ub22:~/tmp$ ./a.out
My PID is 189425
input:123
output:123
input:abc
output:abc
now from another terminal, I do
echo "123" > /proc/189425/fd/0
./a.out got the 123, but did not output it.
input:123
please help me to understand why.
thank you in advance.
Xian