Operating System - HP-UX
1827741 Members
3037 Online
109969 Solutions
New Discussion

Back ground process killed on using Ctrl-C

 
SOLVED
Go to solution
Jason bourne_2
Occasional Advisor

Back ground process killed on using Ctrl-C

Hi,
I have this menu driven script of mine,which i have written on bash shell.There is this option on my menu where i start 2 set of process in the background.Now when i choose the proper exit option from my menu,i dont encounter any problems.But the moment i press Ctrl-C , these background processes get killed.I have tried a lots of option like nohup,onintr,trap,and even tried wrapping my executable call in csh so that the background process does not get the interrupt signal.I also ran through the HP UX manual ,but that dint help me much.Kindly help me in solving this issue.....
26 REPLIES 26
Steven E. Protter
Exalted Contributor
Solution

Re: Back ground process killed on using Ctrl-C

Shalom,

Process management in Posix/HP-UX is different than bash.

http://docs.hp.com/en/5965-4642/5965-4642.pdf

Posix asynchronous I/O (maybe not related.

http://docs.hp.com/en/B9106-90012/ix01.html

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

>I have written on bash shell.

Have you tried using a real shell?

>But the moment I press Control-C, these background processes get killed.

I suppose you could write a SIGINT handler.

>I have tried a lots of option like nohup

I guess that only handles SIGHUP.

If you look at termio(7), it says:
Generates a SIGINT signal which is sent to all processes in the foreground process group for which the terminal is the controlling terminal.

I would have thought that excluded your background processes. But you may have to change them to demons so they aren't affected by the control-C.
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

Hi Steven,
So what exaclty do u say i do to get this problem solved.I want this process to be started through my script itself.Should i change the shell that i am working on,would that help me ...
James R. Ferguson
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

Hi Jason:

> So what exaclty do u say i do to get this problem solved

I would change your script to use the Posix shell and verify that the behavior you want is achieved (it should be). This may be the simplest solution and brings your script in line with HP-UX standards, too.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

Hi (again) Jason:

It might be helpful if you could decompose your script into a small one that fails in your hands and then post that here. I cannot reproduce your problem on a Linux box (for what that's worth).

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

>where I start 2 set of process in the background.

I assume you are redirecting stdout and stderr. Are you redirecting stdin to /dev/null?
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

This is the script that i call from my option ...
James R. Ferguson
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

Hi Jason:

A simple test case is preferred. That said, this statement:

# nohup TradexLocMon trdxdev 2 2 & >>/dev/null

...should probably be:

# nohup TradexLocMon trdxdev 2 >/dev/null 2>&1 &

...which says to run 'TradeexLocMon' as a hangup immune process in the background, passing two arguments ("trdxdev" and "2"). Redirect any STDOUT and STDERR to '/dev/null'.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

Hi (again) Jason:

Perhaps I misunderstood. You said that your last attachment was ..."the script that i call from my option ...".

To start _that_ script in the background you would want to call it as I showed; something like:

# nohup /oath_to_script arg1 arg2 arg3 < /path_to_input > /path_to_output 2>&1 &

The '/path_to_input' and/or '/
path_to_output' can be '/dev/null; if necessary.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Back ground process killed on using Ctrl-C

Shalom,

From the links I posted for you.

nohup script_name &

That will background the processes run them in the background.

Output will go to a nohup.out file

You can with HP-UX use the equivalent of strace (fron Linux), called tusc to trace your process and get specific actions and error codes.

tusc: http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-7.10/

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

hi james ...
yes i have 3 args bck here ....trdxdev,2,2
I tried the below part too...
#nohup TradexLocMon trdxdev 2 2 >/dev/null 2>&1 &
It doesnt seem to work ...could i use "onintr -" to ignore all signals ???
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

Hi Steven
...i dont have "tusc" installed on my server...Is ther any other way that i could track the process.
Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

>Is there any other way that I could track the process?

No, you need to install tusc.

(Have you tried redirecting stdin to /dev/null?)
TTr
Honored Contributor

Re: Back ground process killed on using Ctrl-C

Sorry I can't resit.
With a (last)name like yours I would not have expected you to use bash. If you stuck to your name you would have ended up with the good old sh which is replaced by posix.
Steven E. Protter
Exalted Contributor

Re: Back ground process killed on using Ctrl-C

Shalom,

I install tusc on all my servers.

This is not Linux. You need to add many tools that you would find by default on Linux.

tusc is a basic tool that you should install to track this process.

I 100% back what Dennis says to you.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

Hi, sorry for the late reply.Was busy with some other work.Havnt been able to crack this one yet though.
I have attached my script here below.Please help me on this.Is the shell that i am executing this script a major problem.
James R. Ferguson
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

Hi (again) Jason:

> Havnt been able to crack this one yet though.

As I originally said, it would be much better to decompose your failing script into it's simplest case.

Did you try any of the changes suggested? Did you try using a pure POSIX shell? Why would you want to mix into this a crummy C-shell?

Regards!

...JRF...
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

Hi James R. Ferguson,
Thnx for the reply.Yes i tried lots of things but nothing seems to work .

>Did you try using a pure POSIX shell
Do u say i use sh shell instead of the bash shell.If so how will that differ.I have tried that too.Dint go thru...

>Why would you want to mix into this a crummy C-shell?
Well we have two set of servers here.Linux and HP-UX.I was initially trying to crack this issue on the linux machine and happpend to find that my process was getting killed bcoz the bash shell had a drawback ,where in it is unable to handle an interrupt signal.Thereby killing the background process initiated within.Thus i used the Csh which handled the interrupt signal...

Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

I have no problems using a real shell. The SIGINT is only sent to the first shell:

itrc_background.sh:
#!/usr/bin/sh
# start a background shell and try blocking Control-C
itrc_background.2.sh &
sleep 60

itrc_background.2.sh:
#!/usr/bin/sh
echo "got to $0"
sleep 30
echo "finished with $0"

When I invoke itrc_background.sh, it starts itrc_background.2.sh. If I type Control-C, only itrc_background.sh is killed, itrc_background.2.sh keeps sleeping.
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

@Dennis Handly

Yes i did try this out... But wat i see is when Control-C is pressed, the sleep continues in the background but the process still dies out ...Why is this so ...

Is there anyway is could make the process neglect this interrupt signal like by using something like trap or omintr ...Would changing this help me in any manner ...

Thnx for ur reply ...
Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

>the sleep continues in the background but the process still dies out

The sleep continues and then it echoes the message after sleep. So that case works.
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

@ Dennis Handly
Look mine being a menu driven script i need to continue one activty after the other.So what i did was ,i calld this script in the background, which first starts the process in the background and then the sleep of arnd 30 sec in the background.
On doin so i happend to see that when both sleep and my process are running in the background and if i press Control-C , the sleep still continues, but the process dies out.
Hope you understand what i mean ...
Thnx for the reply ...
Dennis Handly
Acclaimed Contributor

Re: Back ground process killed on using Ctrl-C

>the sleep still continues, but the process dies out. Hope you understand what I mean ...

I thought I did but my small example works fine.

Here is where tusc can help you find what's different in your case and my small example.
Did you ever try redirecting stdin to /dev/null?
Jason bourne_2
Occasional Advisor

Re: Back ground process killed on using Ctrl-C

@ Dennis Handly

> Here is where tusc can help you find what's different in your case
Yes i know but i have a problem here.I dont have tusc installed on my server and installing it aint that easy with all the restrictions applied...(but iam still working on getting it installed).Can i use tusc for all versions of HP-Ux ???

>redirecting stdin
Yes i tried that out too ...
If my executable name is :TradexLocMon
arguments are : 2 and 2
then redirecting it to dev/null would be like this rite..
#TradexLocMon trdxdev 2 2 & 0>/dev/null

Well this dint work either :(
Its that the sleep process doesnt seem to have any problem with the interrupt signal ...Just that my process simply wont stay arnd at that time ;)
Thnx for the reply ....