伪terminal的使用 – C

我使用特定的会话编号创build了一个pThread 。 如果pThread产生了,我试着让另一个进程运行使用openpty启动的伪terminal。

这是代码的一部分:

 if (openpty(&(numa_pst[session][0]),&(numa_pst[session][1]), NULL, NULL, NULL) != 0) { int err_code = errno; sprintf (line_temp, "*** ERROR: numa openpty failed with:\n%s\n", strerror(err_code)); } session = 0; int* pi = calloc(sizeof(int), 1); *pi = session; if (pthread_create(&system_wideThread[session], 0, system_wider, (void*)pi)) { int err_code = errno; sprintf (line_temp, "*** ERROR: System-wide thread spawn failed with:\n%s\n", strerror(err_code)); return 0; } iResult = vfork(); else if (iResult == 0) { close (numa_pst[session][0]); close(1); dup(numa_pst[session][1]) ; sprintf(line, "./perf stat -a -e instructions -e cache-misses -e cache-references -e L1-dcache-loads -e L1-dcache-load-misses -e L1-dcache-stores -e L1-dcache-store-misses -e L1-dcache-prefetch-misses -e bus-cycles -I %i", PROFILING_TIMER); sprintf (line_temp, "%s\n", line); char *cmd[] = {"sh", "-c", line, NULL}; printf("i'm here!"); if (execvp("sh", cmd) < 0){ int err_code = errno; sprintf (line_temp, "*** ERROR: exec failed for system-wide perf with:\n%s\n", strerror(err_code)); } printf("i can't come here, why!?"); } 

但是,数据仍然打印在terminal而不是伪terminal。

任何想法出了什么问题?

这里是一些更多的信息:

 GNU gdb (GDB) 7.6.1-ubuntu Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from bg-service/papcmp...done. (gdb) run perf foobar.txt once Starting program: ./papcmp perf foobar.txt once [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff6db5700 (LWP 24948)] 

该线程已创build! 但没有用,为什么?