Skip to content

solomonw1/basic_shell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic shell

Basic shell with job control. Summary explanation of the shell here.

Core read-eval loop taken from CS:APP. Helper wrapper functions taken from csapp.c.

Functionalities

This shell runs executables in the current working directory or in the specified path.

It can run one process in the foreground and several in the background. The foreground job can be terminated or stopped by typing Ctrl+C or Ctrl+Z, respectively.

Built-in commands: fg, bg, jobs, and quit.

fg and bg accept either the process ID of a running job or the job ID preceded by % as a parameter.

> bg %1      // Resume job with JID=1 on the background
> bg 14501   // Resume job with PID=14501 on the background

Compilation

Either run make or compile as:

gcc -o shell -Wall main.c signals.c jobs.c wrappers.c

Example session

wait and write are dummy executables that run in an infinite loop. The ^C and ^Z characters below are the result of typing Ctrl+C and Ctrl+Z.

> ls
ls: Command not found.
> /bin/ls
jobs.c	 jobs.h   main.c   Makefile   README.md  signals.c   signals.h	wrappers.c   wrappers.h   write
jobs.c~  jobs.h~  main.c~  Makefile~  shell	 signals.c~  wait	wrappers.c~  wrappers.h~
> wait &
[1] 17715			wait &
> wait 
^Z
Job [2] 17716 stopped by signal: Stopped
> fg %2
^C
Job [2] 17716 terminated by signal: Interrupt
> write
1...
1...
1...
1...
^C
Job [2] 17718 terminated by signal: Interrupt
> wait &
[2] 17719			wait &
> jobs
[1] 17715 Running		wait  &
[2] 17719 Running		wait  &
> quit 

About

Basic shell with job control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • C 99.5%
  • Makefile 0.5%