问题
I created a pThread
with a specific session number. If the pThread
is spawned I try to get another process running the pseudo terminal launched using openpty
.
Here is some part of the code:
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!?");
}
However, the data still gets printed in the terminal and not the pseudo terminal.
Any idea what's going wrong?
Here is some more information:
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)]
The thread is created! but not used, Why?
来源:https://stackoverflow.com/questions/24142856/usage-of-pseudo-terminal-c