title: Problem with runing "ps" command on my own linux shell
body: <p>I'm building for a while my own linux shell as part of my academy project. I have reached to a problem when i'm trying to run &quot;ps&quot; command after the command line &quot;/usr/bin/wc text_file.txt&quot;. When I'm trying so - the following error message is shown:</p>
  <pre><code>0: /usr/bin/wc shell.c
    751  3273 24140 shell.c
  1: ps
  error: garbage option
  
  Usage:
   ps [options]
  
   Try 'ps --help &lt;simple|list|output|threads|misc|all&gt;'
    or 'ps --help &lt;s|l|o|t|m|a&gt;'
   for additional help text.
  
  For more details see ps(1).
  </code></pre>
  <p>The followig code is responsible on running the commands in my shell without path (aka &quot;ps&quot;):</p>
  <pre><code>void cmd_commands_without_path(char** parsed,unused struct tokens *tokens) 
  {
      pid_t pid = fork(); // Forking a child 
      char* s = getenv(&quot;PATH&quot;); // Holds the full environment var path.
      int i = 0; // Counter.
      int symbol_counting = 0; // Holds the number of &quot;:&quot; in the full environment path.
      char *temp; // Helps with the initielizing of the new path.
      char *symbol = &quot;/&quot;; // Holds &quot;/&quot; for correcting the new path.
  
  
      /* Puts the user command into an array with NULL in the end. */
      while((tokens_get_token(tokens,i)) != NULL) // While we did not reached to the end of user input.
      {
          parsed[i] = tokens_get_token(tokens,i); // Initielize parsed to hold the user input (command).
          i++;
      }
      parsed[i+1] = NULL; // The end of the user input (command) will be NULL (for execv).
  
      /* Count the number of &quot;:&quot; in the path. */
      for(i = 0; i &lt; strlen(s); i++)
      {
          if(s[i] == ':')
          {
              symbol_counting++; // increasing symbol counting.
          }
      }
      symbol_counting++; // Because have to be an address after the last &quot;:&quot;
      
      if (pid == -1) // If the creation of the child was unsuccessful.
      { 
          printf(&quot;\nFailed forking child..&quot;); 
          return; 
      } 
      else if (pid == 0) // The child was returned.
      { 
       setpgrp(); // Changing the child group id.
       tcsetpgrp(0,getpgrp()); // Return the proccess id of the child.
       
       /* Signals for &quot;ctrl&quot; options. */
       signal(SIGINT,SIG_DFL);
       signal(SIGQUIT,SIG_DFL);
       signal(SIGKILL,SIG_DFL);
       signal(SIGTERM,SIG_DFL);
       signal(SIGTSTP,SIG_DFL);
       signal(SIGCONT,SIG_DFL);
       signal(SIGTTIN,SIG_DFL);
       signal(SIGTTOU,SIG_DFL);
       
          char* full_array[(symbol_counting+1)]; // Create new array at the size of the number of &quot;:&quot;.
          i = 0; // Restarting the counter.
          
          /* Initielize array with the seperate environment variable paths. */
          full_array[i] = strtok(s, &quot;:&quot;);
          for(i = 1; i &lt; symbol_counting; i++)
          {
              full_array[i] = strtok(NULL, &quot;:&quot;);
          }
          
          for(i = 0; i &lt; symbol_counting; i++) // Runs as the number of phats.
          {
              temp = (char*)malloc(MAXLIST*sizeof(char)); // Allocate to temp size of 1024 chars.
              temp[0] = '\0'; // Erasing temp.
          
          if(temp[0] == '\0') // If the word was ended.
          {
              strcpy(temp,full_array[i]); // Adds to temp the path we currently gonna check.
              temp = strcat(temp, symbol); // Adds &quot;/&quot; to the new path.
              temp = strcat(temp, parsed[0]); // Adds to the new path the user command.
              
          
              if(access(temp, X_OK) == 0) // If the command was found in the path.
              {
                  execv(temp,parsed); // Executing the command.
              }
              temp[0] = '\0'; // Erasing temp again.
          }
          }
          return; 
      } 
      else // pid &gt; 0
      { 
          // waiting for child to terminate 
          wait(NULL);
          tcsetpgrp(0,getpgrp()); // Return the proccess id of the child.
          return; 
      } 
  }
  </code></pre>
  <p>I should also say that this error occures only when im trying to run the &quot;ps&quot; command after the command &quot;/usr/bin/wc text.txt&quot;.
  Can anyone give me a clue what i'm doing wrong?</p>