Background Programme in Linux

Posted on 2004-04-05
Last Modified: 2010-04-21
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.
Question by:bugbase
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 45

Expert Comment

ID: 10763325
services in linux are run a daemon processes

check this link

Expert Comment

ID: 10794184
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.

Author Comment

ID: 10819741
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......
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.


Author Comment

ID: 10819763
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.
LVL 45

Expert Comment

ID: 10821029
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

Accepted Solution

ray_pro2 earned 250 total points
ID: 10850890
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.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question