Sponsored Content
Top Forums Programming Help w/ writing a custom Linux shell using x86 assembly (NASM) Post 303003661 by turtle13 on Monday 18th of September 2017 06:45:20 PM
Old 09-18-2017
Help w/ writing a custom Linux shell using x86 assembly (NASM)

Hello world,

I thought this might be a great start to help me with an assignment I have that requires me to write an assembly program that mimics a 32 bit Linux command shell:


When launched, your program will perform the following steps in a loop:


1. Print a prompt, specifically “$ “ to the standard output file

2. Read a single line of input from the standard input file. A line is considered to end when a line feed character (‘\n') is encountered.

3. If the input line is “exit\n” your program must terminate

4. Otherwise, the user's input is to be treated as a command to be executed along with any arguments to be passed to that command.

5. Your program must launch the program specified by the user and pass any provided arguments along to the newly launched program. The program that you launch must, with the exceptions specified below, inherit its environment and standard file handles from your shell program. A single space shall be used to separate individual arguments on the user's supplied command line.

6. If the specified program fails to launch you must print the message: <prog>: command not found before returning to step 1 above. Here the user's desired program name is to be substituted for <prog>. For example
$ foofoo foofoo: command not found
$

7. Otherwise, your shell program must then wait for the program that you launch to complete before it prints its next prompt.

8. Upon completion of the program that was launched, return to step 1.

9. Properly recognize and handle output redirection specified by the user using the “>” (greater than) symbol in a provided command line. Everything to the left of the > is considered the command to execute along with its argument list. The one and only thing to the right of the > is the name of the file to which all of the command's standard output should be saved. The output file must be created with the permissions mask 0644 (that's octal by the way). If your shell cannot successfully open the named output file, you should print an error message (“<file>: Permission denied”) and refuse to execve the named command. For example:
$ /bin/ls -l > /etc/passwd
/etc/passwd: Permission denied
$

10. Properly recognize and handle piping specified by the user using the “|” (vertical bar) symbol in a provided command line. Everything to the left of the | is considered to be the producer command to execute along with its argument list. Everything to the right of the | is considered to be the consumer command to execute along with its argument list. The standard output of the producer process must be connected to the standard input of the consumer process. Your program must wait for BOTH processes to complete before returning to step 1 and printing a prompt.



----

I understand that I will need to use the 'execve' instruction, fork the parent process (shell), and dup2 for redirection.

I'm kinda lost as to where to start. Conceptually I am having a hard time figuring out just how a shell is created out of another shell (if I am even thinking about that the right way).

How should I start this program off, let's say forking the parent shell?
 

9 More Discussions You Might Find Interesting

1. Solaris

custom jumpstart on x86 with DHCP/PXE goes into interactive mode

client boots fine, it gets the ip 192.168.0.10 and the bootfile. Then there is : SunOS 5.10 Version Generic_141445-09 32-bit" ... Configuring devices. Custom JumpStart Reading ZFS config: done Setting up Java. Please wait ... NOTE: Not enough memory for graphical installation. Graphical... (4 Replies)
Discussion started by: TomSu
4 Replies

2. Red Hat

Custom HA agent - Red Hat Linux Cluster

Hi experts, I have some custom application which I need to make Highly Available using red hat cluster service. How do I do it? i know in /usr/share/cluster i shall find HA agents for well known services like Apache or Sybase but I want to write HA agent for my own. I tried looking up on... (4 Replies)
Discussion started by: pshaikh
4 Replies

3. UNIX for Advanced & Expert Users

Writing Custom Builtins for KSH93

I am looking to create some ksh93 extensions using the custom builtin feature. I can successfully create a builtin function, load it using the builtin -f command and get an output. However, I want to get/set values of KSH variables from within my built-in. For example, lets say I am creating... (2 Replies)
Discussion started by: a_programmer
2 Replies

4. UNIX for Dummies Questions & Answers

Linux on custom hardware

I would like to configure a bare minimum Linux with internet browser on a system with Flash & RAM (but no harddisk or any other nonvolatile storage). Please advise. (5 Replies)
Discussion started by: rherb
5 Replies

5. UNIX for Advanced & Expert Users

Help creating a custom linux distro

Hi all, for a while now I've been working on a linux distro and I'm a couple of tweaks away from it to be perfected so if any experts want to help me out please message me. Thanks in advance. (I know I've posted a similar thread on the same topic but it was closed due to an unhelpful title... (0 Replies)
Discussion started by: allk
0 Replies

6. Shell Programming and Scripting

Custom Shell

I have a jump off server, which grants SSH access to a few other servers. I would like to create a custom shell which can be assigned to specific user accounts which runs a menu script upon login, where they can select which server they want to jump too, however should they hit ctrl-c or any... (1 Reply)
Discussion started by: JayC89
1 Replies

7. Shell Programming and Scripting

Ps and top in a custom shell

I am having a hard time wrapping my head around implementing top and ps in a custom shell. What I have is a shell that allows you to do basic commands as you would in a regular bash shell, but when I do the ps command, it gives me all of the processes within my regular bash shell rather than my... (2 Replies)
Discussion started by: Ziun
2 Replies

8. Programming

Custom icons for shell script

Hi, I have an application that I wrote in C using the GTK toolkit that runs on the Linux system. I have a shell script than when run executes two terminals to open a client and server application. I would like to know more on how to create custom start-up icons for my program. ie. using... (1 Reply)
Discussion started by: fedora18
1 Replies

9. UNIX for Advanced & Expert Users

How to create custom options of my own in systemctl Linux?

Hello All, Greetings!! I was trying to create a custom option in systemctl like its out of the box options eg--> status, stop, start, restart, I have tried searching in google but didn't find anything related to it. Basically I would like to create a custom option which is related to... (9 Replies)
Discussion started by: RavinderSingh13
9 Replies
OPENVT(1)							     Linux 1.x								 OPENVT(1)

NAME
openvt - start a program on a new virtual terminal (VT). SYNOPSIS
openvt [-c vtnumber] [OPTIONS] [--] command DESCRIPTION
openvt will find the first available VT, and run on it the given command with the given command options, standard input, output and error are directed to that terminal. The current search path ($PATH) is used to find the requested command. If no command is specified then the environment variable $SHELL is used. OPTIONS -c, --console=VTNUMBER Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work; -f, --force Force opening a VT without checking whether it is already in use; -e, --exec Directly execute the given command, without forking. This option is meant for use in /etc/inittab. If you want to use this feature in another context, be aware that openvt has to be a session leader in order for -e to work. See setsid(2) or setsid(1) on how to achieve this. -s, --switch Switch to the new VT when starting the command. The VT of the new command will be made the new current VT; -u, --user Figure out the owner of the current VT, and run login as that user. Suitable to be called by init. Shouldn't be used with -c or -l; -l, --login Make the command a login shell. A - is prepended to the name of the command to be executed; -v, --verbose Be a bit more verbose; -w, --wait wait for command to complete. If -w and -s are used together then openvt will switch back to the controlling terminal when the com- mand completes; -V, --version print program version and exit; -h, --help show this text and exit. -- end of options to openvt. NOTE
If openvt is compiled with a getopt_long() and you wish to set options to the command to be run, then you must supply the end of options -- flag before the command. EXAMPLES
openvt can be used to start a shell on the next free VT, by using the command: openvt bash To start the shell as a login shell, use: openvt -l bash To get a long listing you must supply the -- separator: openvt -- ls -l HISTORY
Earlier, openvt was called open. It was written by Jon Tombs <jon@gtex02.us.es or jon@robots.ox.ac.uk>. The -w idea is from "sam". SEE ALSO
chvt(1), doshell(8), login(1) 19 Jul 1996 V1.4 OPENVT(1)
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy