LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-11-2009, 04:39 PM   #1
prokhor
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Rep: Reputation: 0
running LISP interpreter as background process


Hi there

I try to run some lisp interpreter as a background process communicating with other applications by reading and writing from files.
The intention is as follows:

- I start the lisp interpreter as a backgroud process
- a file with initial commands (initfile) is loaded
- the interpreter stays active, waiting for additional commands or an exit signal
- every time a new line is added to the initfile (or another specified file) the interpreter reads this line, evaluates it and writes the output to another file
- the interpreter stops when receiving order to do so....

My problem is:

every time the interpreter reaches the initfile's EOF it exits, so I have to reload the whole thing with every new line

I tried:

- clisp <infile >outfile &
- nohup 0<&- 1<infile >outfile &
- nohup 0<&- >/dev/null #no way to communicate

All without success

I hope you can help me, thx

Ps: I am working on a x86 32Bit with linux
 
Old 08-11-2009, 06:24 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,455

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
You could use a fifo:
Code:
#!/bin/sh
mkfifo repl-pipe.fifo

clisp < repl-pipe.fifo > output &
LISP_PID=$!

tail -f input > repl-pipe.fifo &
TAIL_PID=$!

wait $LISP_PID
kill $TAIL_PID
rm repl-pipe.fifo
But it might be better to write a lisp program to listen on a socket.
 
Old 08-12-2009, 02:38 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
if you have an init file for clisp

it's

clisp -i init.lisp

it won't exit then.
and it will be in normal interactive mode.

You cannot monitor a file in the way you suggest.
when you open a file it's read there and then and closed, any
subsequent changes will not work.
A fifo won't do what you want either.

what are you trying to do?

(It's good to see someone using lisp though.)

sockets are easy if you want them...

Last edited by bigearsbilly; 08-12-2009 at 02:42 PM.
 
Old 08-12-2009, 03:06 PM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
Here is a simple socket server...

Code:
(defconstant +portnum+ 50123)
(with-open-stream (socket (socket-accept (socket-server +portnum+)))

    (format t "~&Got a punter..~%")

    (loop
        (eval (read socket)))

)
run it like so:

clisp -i your-init-file socket.lisp

to illustrate it
you can interact in another xterm using netcat

nc localhost 50123
 
Old 08-20-2009, 03:30 PM   #5
prokhor
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bigearsbilly View Post
if you have an init file for clisp



what are you trying to do?

(It's good to see someone using lisp though.)

[/I]
First of all my excuse for the late answer...

I have a program with an output like this:
(root
(class living_thing
(spec human
(prop has_legs))
(spec bird (prop has_wings))))

The program spits that kind of code out whenever it has computed its own input.
Now I have three problems:

1. How do I feed my program time after time (solved by FIFO)
2. How do i lookup the data:
here the problems are:
1. I dont know the structures depht (which is variable) 2. I dont know how to retrieve the information once stored because of 1.
3. How to store it in a DB (solved conceptually by my own)


Any ideas?
 
Old 08-21-2009, 05:47 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
what sort of data structure?
is it a hash-table?

now you wondered why lisp has read macros and prin1
did you know that you can prin1 a lisp data structure out to a file
(a list, a hash table etc.)
then read it back in again as is!
 
  


Reply

Tags
background, bash, clisp, lisp, programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Process running in background baddah Linux - General 3 02-22-2008 12:44 AM
Where is the LISP interpreter?? phoenix_hacker Programming 5 12-27-2006 05:34 PM
running process in background forever danran Linux - General 2 11-19-2006 09:44 AM
background running process elbriga Programming 2 09-21-2004 06:08 PM
Whats a good lisp interpreter? siroxo Linux - Software 0 05-20-2004 05:35 AM


All times are GMT -5. The time now is 06:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration