Strange Ctrl+C behavior


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange Ctrl+C behavior
# 1  
Old 05-08-2017
Oracle Strange Ctrl+C behavior

Hello All,
I have a strange issue. I've created a shell script which connects to RMAN (Oracle Recovery Manager) and executes full DB backup. I then executed this script with nohup and in the background:
Code:
$ nohup my_script.sh > logfile.log 2>&1 &

The issue is that when I tried to take a look into the log:
Code:
tail -f logfile.log

and press Ctrl+C to exit from the tail command I am back in the shell prompt but at the same time RMAN put in the log:
Code:
user interrupt received

I'm not able to understand why RMAN receives the Ctrl+C. Please help me.

Jacek
# 2  
Old 05-08-2017
Depends on the contents of my_script.sh.
# 3  
Old 05-08-2017
My script was:
Code:
#!/bin/bash
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export ORACLE_SID=AGMISMP
rman target / <<EOF
BACKUP  INCREMENTAL LEVEL 0  DATABASE  FORMAT '/%d/DBF-FULL_%s_%U_%T'    TAG 'IPM-11618809'  KEEP UNTIL TIME 'sysdate+100'  RESTORE POINT IPM11618809;
EOF

# 4  
Old 05-11-2017
Any update?
# 5  
Old 05-11-2017
The only possible explanation that comes to mind is somehow the nohupped process clinches to the terminal of its parent process. True, nohup should prevent exactly this, but it is the only way what you said could happen. My gut feeling (without being able to prove that, but you might investigate in this direction) is that in fact the rman binary isn't honoring the request to relinquish the terminal correctly. This would also explain why the complaint comes from there.

The following is not really a solution (for this you probably have to contact Oracle and admonish them for their sloppy programming) but may be a workaround: start the script via an at-job, like this:

Code:
echo "my_script.sh > logfile.log 2>&1" | at <sometime>

at, like cron, doesn't provide its parent process a terminal in first place which it could fail to release. Notice, though, that you might have to set more of a working environment than you did now, because your script inherits from your current environment now but would only inherit from init if called from cron/at. init is notoriously poor when it comes to environment.

I hope this helps.

bakunin
# 6  
Old 05-11-2017
Thanks for the reply, bakunin.
I forgot to tell that "nohup my_script.sh..." is executed inside parent shell script, which was used to prepare my_script.sh
Does this change anything? Smilie
# 7  
Old 05-12-2017
Quote:
Originally Posted by JackK
I forgot to tell that "nohup my_script.sh..." is executed inside parent shell script, which was used to prepare my_script.sh
Does this change anything? Smilie
As it is i already suspected that, so: no, that doesn't change anything.

It is like this: when you start a login shell a "terminal" is created (by a process called getty or something analogous). This terminal is part of the process environment of your login session and is then "inherited" thoughout the process tree originating in your login session. That is, whatever you start from there - foreground processes, background processes, ... - will always use this terminal for any (not-redirected) output. As soon as this terminal ceases to exist (i.e. you log off) all the other processes using this terminal too will also be terminated, because they too lose their terminal.

Now, you might want to have processes continue to run without your session remaining - in fact, this is what most applications are supposed to do: they should continue to run even if the session where they are started ends. One needs a way of telling a process that "yes, there is a terminal, but don't care if it goes away".

For exactly this purpose there is nohup ("no termination on hangup") and this is what it does. Still: this only works if the program honours it (that is: there needs to be some part in the code dealing with it) and second: it doesn't matter if the process is started froma script or by hand: this influences only where in the process tree it is located. Since the purpose of nohup is solely to "disown" the process it doesn't matter how it would otherwise inherit something (the terminal) it now won't.

I hope this explains it.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange behavior of grep

Hi All, I am facing a strange problem while grepping for a process. Here is the small script that i have written. It will look for any process running with the parameter passed to the script. If no process is running it should print appropriate message. $ cat t.ksh #!/bin/ksh set -x ... (9 Replies)
Discussion started by: veeresh_15
9 Replies

2. AIX

Strange behavior with tar

I am trying to create an archive using tar. I am specifying a list of directories using the -L option. For testing purposes I created a simple directory structure: /backup/test /backup/test/test1 /backup/test/test2 The file specified by the -L option, named files.txt, contains:... (8 Replies)
Discussion started by: judykstra
8 Replies

3. Shell Programming and Scripting

Strange behavior on one of my server

I am not sure what is wrong, but I have some strange behavior when printing things out. I do create a file with only one word test, no space, no new line etc. nano file<enter> test<ctrl x>y<enter> Server 1 gets (fail) awk '{print "+"$0"*"}' file *test Server 2 gets (OK) awk '{print... (9 Replies)
Discussion started by: Jotne
9 Replies

4. AIX

Strange memory behavior

Hello together, i have a strange memory behavior on a AIX 7.1 System, which i cannot explain. The Filesystem-Cache will not be grow up and drops often after few minutes. I know if a file was deleted, that the same segment in the FS-Cache will also be cleared. But i am not sure if this is the... (8 Replies)
Discussion started by: -=XrAy=-
8 Replies

5. Ubuntu

Ubuntu strange behavior

It is so till login screen. I mean that when I boot my computer, Ubuntu shows a splash screen with mouse instead of Ubuntu logo and in the login screen it shows XUbuntu login screen... It began when I upgraded to previous kernel, I suppose, but I'm not sure... I can't say that it annoys me very... (6 Replies)
Discussion started by: Sapfeer
6 Replies

6. Programming

Strange behavior in C++

I have the following program: int main(int argc, char** argv){ unsigned long int mean=0; for(int i=1;i<10;i++){ mean+=poisson(12); cout<<mean<<endl; } cout<<"Sum of poisson: "<< mean; return 0; } when I run it, I get the... (4 Replies)
Discussion started by: santiagorf
4 Replies

7. Shell Programming and Scripting

nawk strange behavior

Dear guys; when deleting repeated lines using nawk as below ; Why the below syntax works? nawk ' !a++' infile > outfile and when using the other below syntax the nawk doesn't work? nawk ' { !a++ } ' infile > outfile or nawk ' { !a++ } ' infile > outfile BR (4 Replies)
Discussion started by: ahmad.diab
4 Replies

8. Shell Programming and Scripting

Very Strange Behavior for redirection

I have searched far and wide for an explanation for some odd behavior for output redirection and haven't come up with anything. A co-worker was working on old scripts which have run for years and embedded in their code were output redirects which worked for the script during execution and then... (5 Replies)
Discussion started by: cahook
5 Replies

9. UNIX for Dummies Questions & Answers

strange sed behavior

I have a file called products.kp which contains, for example, 12345678,1^M 87654321,2^M 13579123,3 when I run the command cat products.kp| sed -f kp.sed where kp.sed contains s,^M,, I get the output 12345678,1 87654321,2 13579123,3 (5 Replies)
Discussion started by: Kevin Pryke
5 Replies
Login or Register to Ask a Question