在 gdb 中运行一个简单的程序,该程序派生并执行客户端。execl 行(在 gdb 中的低级 2 内)给出进程 ID“正在执行新程序”,然后立即出现 seg 错误。
到那时的代码如下:
int main(int argc, char *argv[] ) {
/* Create socket pair for communication with server, and fork/exec the server code */
int ret;
int fd[2];
ret = socketpair( AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, fd );
if( ret < 0 ) {
perror( "Unable to create initial socketpair for qrServer" );
return -1;
}
pid_t pid = fork();
if (pid == 0) {
char arg[4];
bzero( arg, 4 );
close(fd[1]);
sprintf( arg, "%d", fd[0] );
char* filename = "child";
ret = execl( filename, filename, arg, NULL );
为了完整起见,子程序开始如下:
int main(int argc, char *argv[] ) {
/* Create socket pair for communication with server, and fork/exec the server code */
if( argc < 2 ) {
perror("Usage: argv[0] <file descriptor>");
有任何想法吗?我什么也没得到,只是段错误本身,我立即得到它。