hi all please help me in this issue.

Hi all,
I am very new to shell scripting.I have the requirement like
one program is there, if it is running leave like that only and if it is stopped it has to be restart and once again keep watching and it is stopped we a have to restart once agian.I want a shell script for this.Please help me in this.

This is an urgent one.Thanks in advance.

Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums

while [ 1 ]
do
   #run your process in background 
   process argument &
   wait $!
   sleep 1
echo 'Restarting'
done

Its working .Thank you very much for ur valuable reply.
Regards,
Vijay

---------- Post updated at 08:07 AM ---------- Previous update was at 08:05 AM ----------

Hi,
Slight modification in my requirement, I want in the code that if the process is killed or aborted when the process is running, It should restart at that time also.
The signals are as below:

switch\(signum\)\{
 case SIGHUP:      return "JVM hangup";
			       break;
 case SIGINT:      return "JVM interrupted";
			       break;
 case SIGQUIT:     return "JVM Quit";
			       break;
 case SIGILL:      return "Illegal instruction";
			       break;
 case SIGABRT:     return "JVM aborted";
		           break;
 case SIGFPE:      return "Floating point exception";
			       break;
 case SIGKILL:     return "JVM killed";
			       break;
 case SIGBUS:      return "Bus error";
			       break;
 case SIGSEGV:     return "Segmentation violation";
			       break;
 case SIGSYS:      return "Bad argument to system call";
			       break;
 case SIGTERM:     return "Software termination signal from kill";
			       break;
 case SIGCHLD:     return "Child process terminated or stopped";
			       break;
 default:          return "JVM abnormally terminated";
			       break;
\}

I dont know how to trap these signals in the script.
Please let me solve in this issue.

Thanks in advance.
Vijay,

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Did you test jonbach script ? No. How I Know it ? Your message is answer. Test first the solution and then ask more, if solution not work or ...

---------- Post updated at 06:20 PM ---------- Previous update was at 04:20 PM ----------

Look trap/signal

---------- Post updated 05-08-09 at 01:42 PM ---------- Previous update was 04-08-09 at 06:20 PM ----------

I got Infractions from this answer. I can't still understand why ?
If we give solution and thread maker not test it, why we give answer ?

Makers first answer was
"Slight modification in my requirement, I want in the code that if the process is killed or aborted when the process is running, It should restart at that time also."

1st solution do it. Later added signal list give more info - then the 1st solution is not anymore answer even it's better - it can handle subprocess in every case, but if you try to restart yourself, you can handle only some interrupts.

If you want others to follow rules, then you should follow rules yourself, right?

First of all, the forum rules are clear on the requirement to post descriptive subject text.

Your original subject text was clearly a rule violation, but our moderators did not give you an infraction for that. They were kind to you.

Then, you are unhappy when someone offers an untested suggestion. Why? Are you paying for the service here? What gives you any right to demand answers from others here in the way you want?

Perhaps English is not your native language. That is OK. However, the rules apply to all, regardless of language.

I hope my reply is clear.

You are welcome to post here, but you should follow the rules. Thanks.

Kshji,

I am very sorry for my misunderstanding of the code.Its because of my poor knowledge.Now I got the one from your precious code.But what I thought is. If i have a program and it is running.Different signals comes into picture.So i want to trap the signals form that program and some functioning for that particular signal.
The signals are,
case SIGHUP
case SIGINT
case SIGQUIT
case SIGILL
case SIGABRT
case SIGFPE
case SIGKILL
case SIGBUS
case SIGSEGV
case SIGSYS
case SIGTERM
case SIGCHLD
This what I required.But i dont know to code these signlas to trap.Now i got the solution for this.If u have any valuable suggestion about the code please share with me.

I am very thankful for the answer you given, Its 100% helped me.

Once agian i am very sorry for mistake.

Thanks,
Vijay,

Now I'm out. Do you mean my update was the reason = link to trap/kill ?
That is added after bhas85 edit the update message: add the ex. about signal list ??? I was unhappy that thead greater not tested 1st solution using every some signals like 1,2,3,9,15, ...

I read my answer again - there is so little mistake - I tried to ask from bhas85 has he/she full tested the johnbach excellent answer. Did you test jonbach script = need edit. As you said, english is not my the best language. Did you test jonbach's script was that what I mean.

Or I have still big problem to understand your opinion. That is also possible.

---------- Post updated at 02:18 PM ---------- Previous update was at 02:11 PM ----------

No problem.

If you like to be sure that you can control process, then make it like 1st johnbach solution has done - wait works in everycase. Make process which control your process. If process get ex. signal 9, you can't catch it yourself, but mother process can live with it = wait has done = so you can't restart yourself. But if you accept this then you can use trap as you have already done.

Kshji,

I tested both of the valuable solutions which is given by you trap/signal and johnbach.The suggested solutions help me a lot in resolving my problem.
If i did any mistake in my posting please pardon me with your kind heart.But the solutions which you gave to me helped alot and made me to understand how to process the signals and to trap the signals.

Thank you very much once again,
Vijay,

OK,

Thanks for the replies,

I think there is some confusion based on language and culture. I will review the thread and make adjustments.

Let's all be more patient with our non-native speaking members, who we have always welcomed.

Enjoy!

---------- Post updated at 12:17 ---------- Previous update was at 11:38 ----------

OK, I was confused in my reply. My apologies. I see now you were not the original poster.

I also see that English is not your native language and you did not intend to insult another member.

Giving you the benefit of doubt, I will reverse your infraction.

Best of luck. (Thead closed)

Note to original poster bhas85: Please follow forum posting rules.