手动生成shell

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/tty.h>
#include <sys/ioctl.h>
       
int main()
{
     
     
     int pid;
     int rc;
 
  setsid();
  ioctl(0, TIOCSCTTY, 0);
  rc = tcsetpgrp(0, getpid());
    printf("rc =%d\n",rc);
   
    pid = fork();
    if (pid < 0)
  {
          printf("error\n");
    }
    if (pid == 0)
    {
        execlp( "/bin/sh", "sh" ,NULL,NULL,NULL);
    }
    else
    {
            wait();
    }
   
    return 0;
   
}

作者: gaocheng   发布时间: 2010-11-10