Thread: problem

  1. #1
    Registered User
    Join Date
    Jun 2005


                   while(1) {  
                    char cmd[20];
                    printf("Shell: "); scanf("%s",&cmd);
    		res = fork();
    		if(res==0) {
    			if((strcmp("ls",cmd))==0) { execl("/bin/ls","ls",NULL); insert_list(list, "ls"); } 
    			if((strcmp("ps",cmd))==0) { execl("/bin/ps","ps",NULL); insert_list(list, "ps"); } 
    			if((strcmp("historic",cmd))==0) {  Print_list(list); }
    		else {
    im creating a little shell, and each time i execute a command i want it to
    be saved in a linked list, so when i execute the command historic, it prints the commands i had executed before. But when i execute command historic the list dont print nothing. I think it is because execl, because if i take the instruction execl("/bin/ls","ls",NULL); it prints the list with the elements correct, in this case ls.
    Sorry about the English.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    How about continuing with the same thread, rather than starting a new thread with a new approach to the same problem.

    People will rapidly start to ignore you if you don't engage in a conversation and just keep posting new threads in the hope that someone will post a solution in response.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM