Visit Our UNIX and Linux User Community


When I am writing my own interpreter...


 
Thread Tools Search this Thread
Top Forums Programming When I am writing my own interpreter...
# 1  
Old 10-15-2007
When I am writing my own interpreter...

While trying out my hand at writing an interpreter, I was wondering about a a few issues one of which is the following: When I run a command such as jobs in the shell, I get a list of all the background jobs that are running... But if I need my interpreter to run that command, how would I be doing it? If I'm not mistaken, jobs is an internal command... So what will I specify in path if I want to run it using the execv command?
# 2  
Old 10-15-2007
job control is internal to the shell, not all shells support job control, for example ksh does, sh doesn't.

If you want job control, manage it yourself, as an internal command, internal list of jobs etc.
# 3  
Old 10-15-2007
Oh.. can you tell me where I should start to be able to do that? I mean what should I read to be able to write code for that...
# 4  
Old 10-15-2007
How about you firstly:

1. decide what the requirements for job control are, what is it trying to achieve, how should it behave etc.

2. then decide how to implement.
# 5  
Old 10-16-2007
A shell is said to have job control if it allows users to put process
int the background and vis-a-vis.


Where to start ... these can be done

how to deal with session , process groups and controlling terminal
how to put process in the background.
signals handling

All the best.
# 6  
Old 10-17-2007
Thanks a lot... I've thought of a few things:

1. I need to maintain a table that contains the job id and the job name.
2. I cannot put a process that is running currently through my interpreter into the background, without first invoking the Stop (CTRL+Z) command.
3. Once I invoke the stop command, I can issue a command bg <process_name> to put the task into the background and then the interpreter will issue a signal to the process to resume itself.
4. If I have to bring a process into the foreground, I need to write code in my interpreter in such a way that it first stops the process and then brings it to the foreground and then resumes it (or get it directly?) and then ceases the command of the shell from the user (invoke a wait command until the process is complete?).

I am little confused about jobs and processes - the difference between them. I hope someone can clarify if my above steps seem ok and also the difference between a job and a process...
# 7  
Old 10-17-2007
The steps you want to follow look ok. The difference between jobs and processes is that a job is specific to the shell that you are running. For example, if you run a background job in a shell and check, say, the jobs command, then you get the jobs list starting from job #1. If you start another shell (inside this one), run another background job and run jobs again, you will get a list again starting from job #1.

This is not true of processes. A pid is a pid no matter which shell you look at it from.

So a job is specific to the shell, while a process runs at the system (OS) level.

Previous Thread | Next Thread
Test Your Knowledge in Computers #298
Difficulty: Easy
Linux Mint actively develops software for its operating system. Most of the development is done in Javascript and the source code is available on GitHub.
True or False?

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamically choosing the interpreter

Hi, Is it possible to choose the inerpreter conditionally. For example, if whereis bash returns /usr/bin/bash then i need to choose #!/usr/bin/bash else i need to use #!/usr/bin/sh. Is it possible to achieve in a shell script? Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

2. Linux

interpreter files

Can you explain me what is ment by interpreter files ?? Why and how they are used?? (1 Reply)
Discussion started by: kkalyan
1 Replies

3. Shell Programming and Scripting

Bad Interpreter

Hi. My name is Caleb (a.k.a RagingNinja) form the whited00r forums. (Whited00r makes custom firmware for iOS devices). I have been learning and creating simple shells scripts. I have been recently using VIM for Windows or using VirtualBox to run the UBUNTU OS within VirtualBox to create my shell... (2 Replies)
Discussion started by: RagingNinja
2 Replies

4. Shell Programming and Scripting

Multiple interpreter declarations

Hi, I am writing a shell script that connects to a remote server and performs some tasks on the server and exits. Since i am using a ssh connection, i am using a "expect" utility to supply the password automatically (which is present within the script). In order to use this utility, i need to... (3 Replies)
Discussion started by: sunrexstar
3 Replies

5. Programming

Java Interpreter

Hello guys - do you have any sample program implementing UNIX commands in an interpreter with Java? I can look up the simple ones such "ls" etc and then write my own commands. I would appreciate it. (2 Replies)
Discussion started by: cmontr
2 Replies

6. UNIX for Dummies Questions & Answers

m4 as script interpreter

#!/usr/bin/m4 when running m4 scripts with "#!/usr/bin/m4" they are executed properly, but "#!/usr/bin/m4" is printed out - how to avoid it? Thanks in advance. (5 Replies)
Discussion started by: Action
5 Replies

7. UNIX for Dummies Questions & Answers

an command interpreter

if somebody can help me pls. i need the source code for a shell which compiles C or java programs. i need a very short and simple one, just for the compiling part, in UNIX Respect (4 Replies)
Discussion started by: zlatan005
4 Replies

Featured Tech Videos