Thread: Creating a command-history feature in self-made shell

  1. #1
    Registered User
    Join Date
    Apr 2022
    Posts
    1

    Creating a command-history feature in self-made shell

    Hello, i've been tasked to create a linux shell using C. every command should run as if it was ran by a standard terminal except the commands "exit" (which was easily implemented) and "history". in history i should print all commands that have been written to the shell (wether they were successful or not) with the PID of the thread that received it:
    $ history
    123 cd asd
    456 ls
    123 ls -l
    456 cd asdflajfd
    456 history
    $
    assume the shell will receive max 100 commands, each in 100 chars length max.
    My question is:
    how do I create an "history array" that is shared with all threads and their "sons", in a way that will achieve the task mentioned above?

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    It seems pretty simple.
    Firstly, you do no usually run shell commands in "threads".
    You usually run them in separate processes.
    The parent process receives the pid of the child (not "son"!), so it's pretty simple to store the pid and command line in an array.
    The history array doesn't need to be accessible to the child processes, only to the parent process.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple shell simulate the linux 'history' command
    By ivar5000 in forum C Programming
    Replies: 5
    Last Post: 10-21-2017, 02:14 AM
  2. History Command Log File
    By Matus in forum Tech Board
    Replies: 1
    Last Post: 04-29-2009, 07:55 PM
  3. using tar command in a shell script
    By rohan_ak1 in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2008, 07:03 AM
  4. little problem with a simple shell program i made.
    By keira in forum Linux Programming
    Replies: 2
    Last Post: 02-26-2008, 11:42 PM
  5. using c++ to use a ms-dos shell command
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2002, 06:23 PM

Tags for this Thread