Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6. #include <unistd.h>
  7.  
  8. int main(){
  9.  
  10. char *input[20];
  11. char *parsed;
  12. char *command;
  13. int index = 0;
  14. char* command2[4];
  15. char* seperator = " ";
  16. char c;
  17. int size;
  18. int stat_loc;
  19. pid_t child_pid;
  20. char** args;
  21.  
  22. while(1){
  23.  
  24. printf("MYSHELL-->");
  25. args = Readline();
  26.  
  27. if (strcmp(command2[0], "cd")== 0){
  28. perror(command2[1]);
  29. }
  30. if (strcmp(command2[0], "logout\n") == 0){
  31. printf("Wollen Sie sich wirklich ausloggen? j/n?: ");
  32. c = getchar();
  33. if (c = 'j'){
  34. return 0;
  35. }
  36. }
  37.  
  38. // for (size_t i = 0; i < sizeof(command2); i++){
  39. // if (strcmp(command2[i], "&\n")==0){
  40. // printf("blalala\n");
  41. // break;
  42. // }
  43. //}
  44.  
  45. //free(input);
  46. //free(command2);
  47.  
  48. }
  49.  
  50. return 0;
  51. }
  52.  
  53. char** Readline(void){
  54. char **command;
  55. int index;
  56. char *seperator= " ";
  57. char* input[20];
  58. char* parsed;
  59.  
  60. fgets(input, 20, stdin);
  61. printf("\n");
  62. parsed = strtok(input, seperator);
  63.  
  64. while (parsed != NULL) {
  65. command[index] = parsed;
  66. index++;
  67. parsed = strtok(NULL, seperator);
  68. }
  69.  
  70. command[index] = NULL;
  71. return command;
  72. }
  73.  
  74. int CreateProcesses
  75.  
  76. child_pid = fork();
  77. if (child_pid == 0 ){
  78. printf("Kindprozess: %d\n", getpid());
  79.  
  80. }
  81. else {
  82. printf(child_pid);
  83. printf("\n");
  84. waitpid(child_pid, &stat_loc, WUNTRACED);
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement