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?
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
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Programming
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
5. Ubuntu
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. AIX
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
7. Shell Programming and Scripting
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
8. AIX
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
9. Shell Programming and Scripting
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
LEARN ABOUT DEBIAN
tcgetpgrp
TCGETPGRP(3) Linux Programmer's Manual TCGETPGRP(3)
NAME
tcgetpgrp, tcsetpgrp - get and set terminal foreground process group
SYNOPSIS
#include <unistd.h>
pid_t tcgetpgrp(int fd);
int tcsetpgrp(int fd, pid_t pgrp);
DESCRIPTION
The function tcgetpgrp() returns the process group ID of the foreground process group on the terminal associated to fd, which must be the
controlling terminal of the calling process.
The function tcsetpgrp() makes the process group with process group ID pgrp the foreground process group on the terminal associated to fd,
which must be the controlling terminal of the calling process, and still be associated with its session. Moreover, pgrp must be a
(nonempty) process group belonging to the same session as the calling process.
If tcsetpgrp() is called by a member of a background process group in its session, and the calling process is not blocking or ignoring
SIGTTOU, a SIGTTOU signal is sent to all members of this background process group.
RETURN VALUE
When fd refers to the controlling terminal of the calling process, the function tcgetpgrp() will return the foreground process group ID of
that terminal if there is one, and some value larger than 1 that is not presently a process group ID otherwise. When fd does not refer to
the controlling terminal of the calling process, -1 is returned, and errno is set appropriately.
When successful, tcsetpgrp() returns 0. Otherwise, it returns -1, and errno is set appropriately.
ERRORS
EBADF fd is not a valid file descriptor.
EINVAL pgrp has an unsupported value.
ENOTTY The calling process does not have a controlling terminal, or it has one but it is not described by fd, or, for tcsetpgrp(), this
controlling terminal is no longer associated with the session of the calling process.
EPERM pgrp has a supported value, but is not the process group ID of a process in the same session as the calling process.
CONFORMING TO
POSIX.1-2001.
NOTES
These functions are implemented via the TIOCGPGRP and TIOCSPGRP ioctls.
History
The ioctls appeared in 4.2BSD. The functions are POSIX inventions.
SEE ALSO
setpgid(2), setsid(2), credentials(7)
COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2003-01-28 TCGETPGRP(3)