14 Haziran 2015 Pazar

Change Directory chdir and getcwd example

Hello everyone , this article for my linux exam. I hope it's beneficial for every computer science student. This programme firstly shows current working directory after that takes new directory command with scanf.If you have any trouble with this topic just send me e-mail : enes065@gmail.com .


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char** argv)
{
pid_t child_pid;
 char *message;
  char s[500];
   char* cwd;
    char buff[500];
     char *directory  ;
      int ret;

int repetition;
printf("So far only one process is runing\n");
child_pid = fork();
switch (child_pid)
{
case -1:
printf("fork process failed\n");
exit(1);

case 0:
message = "J am a child";
 printf( "My working directory is %s.\n", getcwd(buff, 500));
 printf("New directory: \n");
         scanf("%s",s);
         chdir(s);

break;
default:
message = "J am a parent";

break;
}
printf( "My working directory is %s.\n", getcwd(s, 500));
}

Hiç yorum yok:

Yorum Gönder

Yorum yaptığınız için teşekkür ederiz.