When I am writing my own interpreter...


 
Thread Tools Search this Thread
Top Forums Programming When I am writing my own interpreter...
# 29  
Old 10-26-2007
Presumably because the shell itself still has both ends of both pipes still open.

Try adding

close(pipe_a[0]);
close(pipe_a[1]);
close(pipe_b[0]);
close(pipe_b[1]);

prior to your wait.

When your shell exits, these file descriptors get closed, hence allowing EOF to be read. EOF will never be read while there is a write end open.
# 30  
Old 10-26-2007
Oh... Sounds like that... Now, I'm getting the required output but it still has that defunct word besides it... Now all the three have that word....
# 31  
Old 10-26-2007
Are you going to reap all of your children?

When a child dies (see SIGCHLD) you need to call wait/wait4/waitpid to get the exit code to stop the process being a zombie.

You have a number of processes that you did not do a wait for.

In synchronous programming you do

pid=fork();

if (!pid) { child stuff; _exit(1); }

waitpid(pid,....);
# 32  
Old 10-26-2007
Well yeah.... I am using exit(1). The reason why I'm not using it here in this code is because I cannot use it in the first place... because when I'm using execlp it doesn't give me the control back....
# 33  
Old 10-26-2007
But in your example all of the processes are children of the shell. You do the wait as the parent of the fork().

Hence the shell should still reap them.

As a test, put the following in the code for each child after the fork()...

fprintf(stderr,"I am %d, my parent is %d\n",getpid(),getppid());
fflush(stderr);
# 34  
Old 11-08-2007
I guess I now understand why you asked me to use Structures porter Sir... I guess I've had my piece of cake.. I'll rewrite this thing... I've already thought of a good structure so I guess will implement that now... Guess experience counts in situations like these... Smilie I'll update as soon as I finish writing that model...
# 35  
Old 11-08-2007
Quote:
Originally Posted by Legend986
Guess experience counts in situations like these... Smilie
That's what it's all about, there are no right and wrong answers (apart from ones that don't actually work) and many ways to skin a cat.

But there are often solutions that are better, simpler or more elegant. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question