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
GENCCODE(8)							 ICU 50.1.2 Manual						       GENCCODE(8)

NAME
genccode - generate C or platform specific assembly code from an ICU data file. SYNOPSIS
genccode [ -h, -?, --help ] [ -a, --assembly name ] [ -d, --destdir destination ] [ -n, --name name ] [ -e, --entrypoint name ] [ -f, --filename name ] [ filename ... ] DESCRIPTION
genccode reads each of the supplied filename and writes out a C file containing a compilable definition of the data in the data file. The C file name is made by taking the base name of the data filename, replacing dots by underscores, and adding a .c file extension. If the -a option is used, platform specific assembly code is generated instead of C code. Most C compilers will accept both C and assembly files. Instead of writing a filename with a .c file extension, a filename with a .s will be written instead. If genccode is called with no filename it terminates gracefully. OPTIONS
-h, -?, --help Print help about usage and exit. -a, --assembly name Output assembly code instead of C code. Use -h to see the list of available types of assembly to generate and to specify for this option. -d, --destdir destination Set the destination directory to destination. The default destination directory is the current directory. -n, --name name Set the data name to name instead of the default. This name is also used as the base name of the output. The default name is made of the icudt prefix, followed by a two-digit version number corresponding to the current version of the ICU release, and a single let- ter indicating the endianness of the data (the letter b indicated big endian data, and the letter l indicates little endian ones). -f, --filename name Normally, an ICU data file such as mydata.icu will be turned into mydata_icu.c and mydata_icu.o. However, if this parameter was set to "somedata", the output files will be somedata.o and somedata.c, respectively. -e, --entrypoint name Set the data entry point (used for linking against the data in a shared library form) to name. The default entry point name is made of the data (set by the -n, --name option) followed by an underscore and the type of the data (set by the -t, --type option). VERSION
50.1.2 COPYRIGHT
Copyright (C) 2000-2004 IBM, Inc. and others. ICU MANPAGE
11 March 2004 GENCCODE(8)
All times are GMT -4. The time now is 04:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy