Solved

Background Programme in Linux

Posted on 2004-04-05
6
393 Views
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.
0
Comment
Question by:bugbase
  • 2
  • 2
  • 2
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10763325
services in linux are run a daemon processes

check this link
http://www.linuxjournal.com/article.php?sid=2335
0
 

Expert Comment

by:ray_pro2
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.
0
 

Author Comment

by:bugbase
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......
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:bugbase
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.
0
 
LVL 45

Expert Comment

by:sunnycoder
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
http://www.comptechdoc.org/os/linux/startupman/index.html
man init
0
 

Accepted Solution

by:
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now