a simple example, Strange problem running in the background, about shell program.
a simple example, Strange problem running in the background, about shell program.
the "test.c" file is:
#include <stdio.h>
int main()
{
printf("\nstart test\n");
while(1)
{
printf("type 'X' to exit\n");
if('X' == fgetc(stdin))
break;
}
printf("\nend test\n");
return 0;
}
the "test.sh" file is:
#!/bin/bash
# test.sh
./test &
Compile test.c generates executable file test:
$ gcc -o test test.c
on the command line Executed directly test :
$ ./test &
[1] 10602
start test
type 'X' to exit
[1]+ Stopped ./test
But, execute the test.sh,why does the terminal constantly display “type 'X' to exit” ???
$ sh test.sh
type 'X' to exit
type 'X' to exit
type 'X' to exit
type 'X' to exit
............
|