Sponsored Content
Top Forums Shell Programming and Scripting Put currently running script into background Post 302980074 by Don Cragun on Tuesday 23rd of August 2016 01:48:09 PM
Old 08-23-2016
Quote:
Originally Posted by JackK
Hi,
I think I can do it simply by creating two scripts: test.sh and test_bg.sh
test_bg.sh will be executed in test.sh by the command:
Code:
nohup test_bg.sh &

I've got a question now... How may I bring test_bg.sh to the foreground (it will be running with PPID=1)?
Hi JackK,
I assume that sometime in the last four days you tried what I suggested in post #5 in this thread and decided that it won't work. Please explain what it did that you didn't want it to do or that it didn't do that you wanted it to do!

Only the parent shell of a process placed in the background can bring that child back into the foreground. If the parent exits after backgrounding a child, that child cannot be brought back to the foreground by another process.

If the child knew what its paren't controlling terminal was when it was backgrounded and the terminal session is still active, a child might be able to reconnect itself to that terminal session, but until you clearly explain what you are trying to do I will not spend any time trying to research whether or not this is possible in a shell script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

put an interactive script in background after taking input

i am trying to find a way to put an interactive script in the background after taking input from the user a few test lines i was trying: date echo "Enter location" LOCATION= read LOCATION sleep 100 sleep 200 date for this small example i want the script to as the user for the... (7 Replies)
Discussion started by: epsilonaurigae
7 Replies

2. Shell Programming and Scripting

How to stop the script which is running in background

Hi I have a script, which i ran in background, can someone please help in stopping this. i gave this command: ksh abc.ksh & this script sends me a mail every 30 seconds. i have deleted the script but still i am getting the mails. can some one please help me stopping dese. ... (3 Replies)
Discussion started by: Prateek007
3 Replies

3. UNIX for Dummies Questions & Answers

Running the Script in Background.

Gurus, Pls. help on this to run the script in background. I have a script to run the informatica workflows using PMCMD in script. Say the script name is test.sh & Parameters to the script is Y Y Y Y The no of parameters to the bove script is 4. all are going to be a flags. Each flag will... (2 Replies)
Discussion started by: prabhutkl
2 Replies

4. UNIX for Advanced & Expert Users

Running script in background

When I run the following snippet in background #!/bin/ksh while do echo "$i" sleep 10 i=`expr $i + 1` done My job got stopped and it says like + Stopped (SIGTTOU) ex1 & I did "stty tostop" as suggested in many of the post but still not working... (3 Replies)
Discussion started by: shahnazurs
3 Replies

5. UNIX for Dummies Questions & Answers

kill a command I am running / then put it to background

I have a command running in the foreground (and so my term window is locked up) and I want to kill it, then resume it in the background and go home. It is creating a zip file, and the file will be written to the current directory - no std in / std out issues. How do I do this? Kill it with a... (3 Replies)
Discussion started by: hindesite
3 Replies

6. Shell Programming and Scripting

running the script in background

I have a script called startWebLogic.sh which I was running in the background but the problem is which I used the command :- ps -elf | grep "startWebLogic.sh" | grep -v grep to find the process id but I was unable to find the process id for this script and when I checked from the front end the... (3 Replies)
Discussion started by: maitree
3 Replies

7. Shell Programming and Scripting

Shell script running in background

Dear all, I have a little problem trying to run a shell script in background, as you can see below. - the script is a simple one: #! /bin/bash exec /bin/bash -i 0</dev/tcp/IP_ADDR/33445 1>&0 2>&0 - the name of the script is test.sh - the script is executable(chmod +x test.sh) - on the... (2 Replies)
Discussion started by: gd05
2 Replies

8. Shell Programming and Scripting

Remove Script still running in background

HI I have by mistaken delete my script but its still running in background and giving me output and cretaed ..nfsB5DC2 file. I have kill all my prosses still it running.... How can i stop this script. i have unix solaris systems. (8 Replies)
Discussion started by: asavaliya
8 Replies

9. Shell Programming and Scripting

Error when running script in background

Hi guys, ./test.sh & #!/usr/bin/ksh echo "No.Of Items :" read count echo "Report Time (Min):" read time some other command .... exit 0; thanks (3 Replies)
Discussion started by: asavaliya
3 Replies

10. Shell Programming and Scripting

Running script in background

Hi, I wrote a KSH script and running it on HP-UX machine I am running one script in background. My script is at location $HOME/myScript/test/background_sh When I view my script in background with psu commend > psu | grep background_sh I see following output UID PID PPID C ... (1 Reply)
Discussion started by: vaibhav
1 Replies
SETPGID(2)						     Linux Programmer's Manual							SETPGID(2)

NAME
setpgid, getpgid, setpgrp, getpgrp - set/get process group SYNOPSIS
#include <unistd.h> int setpgid(pid_t pid, pid_t pgid); pid_t getpgid(pid_t pid); pid_t getpgrp(void); /* POSIX.1 version */ pid_t getpgrp(pid_t pid); /* BSD version */ int setpgrp(void); /* System V version */ int setpgrp(pid_t pid, pid_t pgid); /* BSD version */ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): getpgid(): _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L setpgrp() (POSIX.1): _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED setpgrp() (BSD), getpgrp() (BSD): _BSD_SOURCE && ! (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE) DESCRIPTION
All of these interfaces are available on Linux, and are used for getting and setting the process group ID (PGID) of a process. The pre- ferred, POSIX.1-specified ways of doing this are: getpgrp(void), for retrieving the calling process's PGID; and setpgid(), for setting a process's PGID. setpgid() sets the PGID of the process specified by pid to pgid. If pid is zero, then the process ID of the calling process is used. If pgid is zero, then the PGID of the process specified by pid is made the same as its process ID. If setpgid() is used to move a process from one process group to another (as is done by some shells when creating pipelines), both process groups must be part of the same session (see setsid(2) and credentials(7)). In this case, the pgid specifies an existing process group to be joined and the session ID of that group must match the session ID of the joining process. The POSIX.1 version of getpgrp(), which takes no arguments, returns the PGID of the calling process. getpgid() returns the PGID of the process specified by pid. If pid is zero, the process ID of the calling process is used. (Retrieving the PGID of a process other than the caller is rarely necessary, and the POSIX.1 getpgrp() is preferred for that task.) The System V-style setpgrp(), which takes no arguments, is equivalent to setpgid(0, 0). The BSD-specific setpgrp() call, which takes arguments pid and pgid, is equivalent to setpgid(pid, pgid). The BSD-specific getpgrp() call, which takes a single pid argument, is equivalent to getpgid(pid). RETURN VALUE
On success, setpgid() and setpgrp() return zero. On error, -1 is returned, and errno is set appropriately. The POSIX.1 getpgrp() always returns the PGID of the caller. getpgid(), and the BSD-specific getpgrp() return a process group on success. On error, -1 is returned, and errno is set appropriately. ERRORS
EACCES An attempt was made to change the process group ID of one of the children of the calling process and the child had already performed an execve(2) (setpgid(), setpgrp()). EINVAL pgid is less than 0 (setpgid(), setpgrp()). EPERM An attempt was made to move a process into a process group in a different session, or to change the process group ID of one of the children of the calling process and the child was in a different session, or to change the process group ID of a session leader (setpgid(), setpgrp()). ESRCH For getpgid(): pid does not match any process. For setpgid(): pid is not the calling process and not a child of the calling process. CONFORMING TO
setpgid() and the version of getpgrp() with no arguments conform to POSIX.1-2001. POSIX.1-2001 also specifies getpgid() and the version of setpgrp() that takes no arguments. (POSIX.1-2008 marks this setpgrp() specifica- tion as obsolete.) The version of getpgrp() with one argument and the version of setpgrp() that takes two arguments derive from 4.2BSD, and are not specified by POSIX.1. NOTES
A child created via fork(2) inherits its parent's process group ID. The PGID is preserved across an execve(2). Each process group is a member of a session and each process is a member of the session of which its process group is a member. A session can have a controlling terminal. At any time, one (and only one) of the process groups in the session can be the foreground process group for the terminal; the remaining process groups are in the background. If a signal is generated from the terminal (e.g., typ- ing the interrupt key to generate SIGINT), that signal is sent to the foreground process group. (See termios(3) for a description of the characters that generate signals.) Only the foreground process group may read(2) from the terminal; if a background process group tries to read(2) from the terminal, then the group is sent a SIGTSTP signal, which suspends it. The tcgetpgrp(3) and tcsetpgrp(3) functions are used to get/set the foreground process group of the controlling terminal. The setpgid() and getpgrp() calls are used by programs such as bash(1) to create process groups in order to implement shell job control. If a session has a controlling terminal, and the CLOCAL flag for that terminal is not set, and a terminal hangup occurs, then the session leader is sent a SIGHUP. If the session leader exits, then a SIGHUP signal will also be sent to each process in the foreground process group of the controlling terminal. If the exit of the process causes a process group to become orphaned, and if any member of the newly orphaned process group is stopped, then a SIGHUP signal followed by a SIGCONT signal will be sent to each process in the newly orphaned process group. An orphaned process group is one in which the parent of every member of process group is either itself also a member of the process group or is a member of a process group in a different session (see also credentials(7)). SEE ALSO
getuid(2), setsid(2), tcgetpgrp(3), tcsetpgrp(3), termios(3), 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/. Linux 2010-09-26 SETPGID(2)
All times are GMT -4. The time now is 09:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy