我创建了一个具有特定会话编号的pThread
。如果生成pThread
,我会尝试使用openpty
启动另一个运行伪终端的进程。
以下是代码的一部分:
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!?");
}
但是,数据仍会在终端中打印而不是伪终端。
知道出了什么问题吗?
以下是一些更多信息:
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)]
线程已创建!但没用过,为什么?