• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

Background Programme in Linux

I've written a SMS system in java. I need that system to be executed in the linux background (as services in win2k). How can I do it ?. I use a *.jar file in my system.
  • 2
  • 2
  • 2
1 Solution
services in linux are run a daemon processes

check this link
There are 3 ways of doing it :
1. Make it run as a daemon.
2. Try the conventional & to push the process to the background(typeing 'jar <filename>.jar &' should do the trick.
3. Put the process(if need be, using an intermediate shell script containig the line : 'jar <filename>.jar ') in the startup list.

If these are not wht you want, please specify if you want the process to get started during startup.
bugbaseAuthor Commented:
This is the thing I'm a new bie to Linux so that I dont know how to Shell program. I need a program kind of thing to work that out.

Lets say I have mySys.jar, Can u show how to do it step by step......
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

bugbaseAuthor Commented:
Yes I want to start the process @ start up too. I use a configuration file too to get environment from the system and in my jar file I use a class named Service to the start the system.
write the command that needs to be run into a script and put the script at oneof /etc/rc* dir
replace * with appropriate run level

read this link and man page for init for more information
man init
Let us do it a step at a time.....

1. How to write a shell program ?
   Very simple.

   step 1 : open a plain text file, using your favourite text editor. I will assume the use of vi editor.  Let the name of your first shell program be script1. Then you can open it using vi by typing the command
                        $ vi script1 [enter]

   step 2 : The shell has an embedded programming language. It understands all the linux commands available in your system, combined with some programming languagfe like constructs.
Let us write a simple script, that complies and runs a jar program, if there are no errors during compilation. Of course the source filename has to be supplied as the first argument. Type these lines of code in the file script1:

             #All comment line start with #.
             #This line executes the command jar, with the first argument to the shell script as
              #its source.
             jar $1 &

    step 3 : save this file (here press :Esc, then :, then wq and then Enter). Give execute permission to this script by typing the command:

               $ chmod 755 script1

    step 4 : Now your shell program is ready to run. If you want to complie and run the program mySys.jar, writting this line should do (provided, both mySys.jar and script1 are in the current directory):

                $ ./script1 mySys.jar

The '&' in the script puts the process in the background. The philosophy of shell scripting/programming is very straightforward. A linux shell executs commands that you type into a terminal. Internally, linux like any other UNIX system treats your terminal as a file, in which the commands are present in the form of character strings. The speciality of the linux (or any UNIX) shell is that, it can not only execute commands from the terminal file, but also from any other file(like script1 above). This is conceptually very similar to the batch file of MS-DOS. But a shell script/program can do much more than just executing commands in a batch. It can also provide programming constructs like if, if-then-else, case-construce, for loop, while loop, until loop, functions and much more.

2.  How to put the program in startup?

    Since you have not been specific, I assume Red Hat Linux 8.0 or higher running in Gnome Desktop mode. Follow the steps to put your shell script in start-up:

    1. Double click 'Start-Here' icon on your desktop. A file manager window will open up.
    2. Double click the 'Preferences' icon.
    3. Double click the 'Extras' icon.
    4. Double click the 'Sessions' icon.
    5. Select the 'startup programs' tab.
    6. Click the 'add' button.
    7. specify the path of your script in the space provided and click 'OK'.

Next time you boot up, you will find your program getting started up at Startup. Make sure that you have given your script execute permissions before you put it at startup.

If you are still not clear about the 'Shell programming' thing, next time be more specific about your intensions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now