Permalink
Browse files

尝试给命令加

  • Loading branch information...
1 parent 3c50154 commit ecc9288b2377900a5eaf1d0e8842cd6038cbd335 @Yemsheng committed Oct 23, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 my_shell.c
View
@@ -5,12 +5,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
+#include <fcntl.h>
+#include <sys/stat.h>
int main(void)
{
//char argv[10][10];
//memset(argv, 0, sizeof(argv));
- char *argv[] = {"ls", NULL};
+ char *argv[] = {"ls","-l", "-R", NULL};
char *envp[] = {"PATH=/BIN:/usr/bin", "TERM=console", NULL};
extern char **environ;
@@ -25,9 +27,18 @@ int main(void)
}
if(pid==0)
{
+ int fd;
printf("this is child running\n");
- sleep(3);
+ sleep(1);
//execve(argv[0], argv, envp);
+ fd = open("file1", O_CREAT|O_RDWR, S_IRUSR|S_IWUSR);
+ if(fd<0)
+ {
+ perror("open\n");
+ exit(1);
+ }
+ dup2(fd, 1);
+ close(fd);
execvp(argv[0], argv);
perror("execvp error\n");
exit(1);

0 comments on commit ecc9288

Please sign in to comment.