1 /* from http://jwz.livejournal.com/817438.html */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <pty.h>
6
7 static int
do_fork(void)8 do_fork(void)
9 {
10 int fd = -1;
11 pid_t pid;
12
13 if ((pid = forkpty(&fd, NULL, NULL, NULL)) < 0)
14 perror("forkpty");
15 else if (!pid)
16 {
17 printf ("0123456789\n");
18
19 /* #### Uncommenting this makes it work! */
20 /* sleep(20); */
21
22 exit (0);
23 }
24
25 return fd;
26 }
27
28
29 int
main(int argc,char ** argv)30 main (int argc, char **argv)
31 {
32 char s[1024];
33 int n;
34 int fd = do_fork();
35
36 /* On 10.4, this prints the whole 10 character line, 1 char per second.
37 On 10.5, it prints 1 character and stops.
38 */
39 do {
40 n = read (fd, s, 1);
41 if (n > 0) fprintf (stderr, "%c", *s);
42 sleep (1);
43 } while (n > 0);
44
45 return 0;
46 }
47
48