4 Replies - 186 Views - Last Post: 28 February 2018 - 10:46 AM Rate Topic: -----

#1 patriotaki   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

Linux Shell Implentation in C

Posted 28 February 2018 - 06:19 AM

Hello ive got an assignment to do, its basically a linux shell implentation
i have completed so far 3/4 sections of it
1. Custom commands like cd,exit etc (done)
2. Pipes (done)
3. Redirection (done)
4. Background proccessing

im stuck at this section, the assignment says that when a user presses CTRL-Z the process should go as a background process and when the user enters "fg" the same processs should come back in the foreground

my questions are..

1) how can i listen to keyboard input?
2) what about the commands that are too fast to execute like "ls" ?

i guess that commands with "&" will go in background,
but how will i press ctrl z? that usually terminates the execution

Is This A Good Question/Topic? 0
  • +

Replies To: Linux Shell Implentation in C

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6285
  • View blog
  • Posts: 21,608
  • Joined: 05-May 12

Re: Linux Shell Implentation in C

Posted 28 February 2018 - 06:42 AM

How are you currently getting input from the user? If you are using C's standard input, then you will have to change that to lower level code that actually reads the console keyboard inputs. If you are on a *nix platform, then the curses library will be your friend. If you are on Windows, learn how to use the Windows Console APIs.
Was This Post Helpful? 0
  • +
  • -

#3 patriotaki   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

Re: Linux Shell Implentation in C

Posted 28 February 2018 - 06:51 AM

i use getline function to read the line

im not sure if we are allowed to use other external libraries

This post has been edited by Skydiver: 28 February 2018 - 08:09 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 patriotaki   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

Re: Linux Shell Implentation in C

Posted 28 February 2018 - 07:30 AM

Skydiver
maybe i can use signals?
with signal(SIGINT, sighandler); you can catch CTRL + C maybe i can use something simialr to catch CTRL Q,CTRL S ,CTRL Z etc?

This post has been edited by patriotaki: 28 February 2018 - 07:31 AM

Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6285
  • View blog
  • Posts: 21,608
  • Joined: 05-May 12

Re: Linux Shell Implentation in C

Posted 28 February 2018 - 10:46 AM

Give it a try and find out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1