Killing an Xterm while leaving subprocess alive...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Killing an Xterm while leaving subprocess alive...
# 1  
Old 10-21-2005
Killing an Xterm while leaving subprocess alive...

Hi,
I'm not quite understanding what I'm doing (happens often). This pseudocode works:

#!/bin/pseudoksh

function kill_parent {
when i_want_to ; do
sleep 2
kill -TERM $PPID
exit
done
}

kill_parent &
ssh remote_host sh <<-EOF
notify_kill_parent # let the bg function know it's ok to kill parent
run_command # something x-based
EOF


Now, if I start my script in an xterm:
xterm -e run_my_script
It works as expected! The xterm pops up, ssh queries me for a password, the command runs and displays, and, seconds later, the xterm is killed. This is what I want to have happen. But I'm not sure why the remote shell and my application (run_command, above) still stick around. I've been pretty sloppy with stdin/stdout so I'm surprised they don't disappear when I kill the parent (xterm).

I'm happy it works, but I'm worried about a bug creeping in later- for example, since I'm not handling stdout, am I in danger of filling a buffer that is going to make the app hang? Or something like this.

I'm looking for insight into what happens when xterm calls ssh which calls a shell which calls a command. Xterm dies but the command does not. Why?
Thanks.
-Schwage
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Python] - subprocess issue

So I have this basic script, see below import subprocess import shlex command = "gcloud projects list" subprocess.check_output(shlex.split(command)) subprocess.check_call(shlex.split(command)) The subprocess.check_call(shlex.split(command)) actually return what I expect. It returns... (6 Replies)
Discussion started by: scj2012
6 Replies

2. Shell Programming and Scripting

Python3 subprocess troubles

After struggling with this for days now, I'm reaching out to the experts of all things linux for some help with this. I'm trying to run the following working command (on command line) inside a python script using subprocess: rsync -avzh --no-perms --delete --include="*sub*" --exclude='*'... (2 Replies)
Discussion started by: timj123
2 Replies

3. UNIX for Advanced & Expert Users

Trapping a kill command sent to a script and using it to send an EOF to a subprocess before killing

I originally had a script written in pure shell that I used to parse logs in real time and create a pipe delimited file that only contained errors. It worked but it was using a lot of memory (still not clear on why). I originally got around this by writing a wrapper for the script that ran on cron... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

4. Shell Programming and Scripting

Python subprocess

Hi guys, I'm learning python and perl and i was trying to run from python a perl script using the subprocess module. I have an issue that i don't understand regarding this. I run this code: #!/usr/bin/python import subprocess p2 = subprocess.Popen(,stdout=subprocess.PIPE) output2 =... (2 Replies)
Discussion started by: capitanui
2 Replies

5. Shell Programming and Scripting

Xterm using python subprocess

Hi, I am trying to run a shell script using subprocess in python. I can run simple script with arguments using subprocess.But I am not able to embed xterm in subrocess command. #!/usr/bin/python import subprocess subprocess.call() Above code gives me error. Please help me in... (2 Replies)
Discussion started by: diehard
2 Replies

6. AIX

Subprocess errors

Hi Guys, Just a question about subprocesses.. Lately one of our servers has started to throw out the following error: SYSTEM ERROR: Too many subprocesses, cannot fork. Errno=12 We've already increased the threshold twice. Its now up to 8000 and the swap space has also been increased. We... (6 Replies)
Discussion started by: Jazmania
6 Replies

7. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

8. Shell Programming and Scripting

Doubt about pipes and subprocess

Hi, I am having a trivial doubt. Please see the below pipeline code sequence. command1 | (command 2; commend 3) I am aware that the command that follows pipe will run in the sub shell by the Unix kernel. But how about here? Since these set of commands are grouped under "parantheses", will... (6 Replies)
Discussion started by: royalibrahim
6 Replies

9. Shell Programming and Scripting

Leaving Program running but killing the script

Sorry for all the threads. I am almost done. I ahve a bash script that is launching a diags program then copying the .html over my client. then it does the following line /opt/firefox/firefox report.html it launches it fines but the program waits for me to close the window or kill the script.... (2 Replies)
Discussion started by: deaconf19
2 Replies

10. Shell Programming and Scripting

check if job still alive and killing it after a certain walltime

Hi! I'm using a script to start a process that might run forever if some parameters are given wrong (it's part of an optimization). I would now like to have the process killed after a certain walltime in that case. So far I get it done with the following lines ./My_process.e & pid=`ps -ef |... (3 Replies)
Discussion started by: ciwstevie
3 Replies
Login or Register to Ask a Question
wait(1) 							   User Commands							   wait(1)

NAME
wait - await process completion SYNOPSIS
/bin/sh wait [pid]... /bin/jsh /bin/ksh /usr/xpg4/bin/sh wait [pid]... wait [% jobid...] /bin/csh wait ksh93 wait [job...] DESCRIPTION
The shell itself executes wait, without creating a new process. If you get the error message cannot fork,too many processes, try using the wait command to clean up your background processes. If this doesn't help, the system process table is probably full or you have too many active foreground processes. There is a limit to the number of process IDs associated with your login, and to the number the system can keep track of. Not all the processes of a pipeline with three or more stages are children of the shell, and thus cannot be waited for. /bin/sh, /bin/jsh Wait for your background process whose process ID is pid and report its termination status. If pid is omitted, all your shell's currently active background processes are waited for and the return code is 0. The wait utility accepts a job identifier, when Job Control is enabled (jsh), and the argument, jobid, is preceded by a percent sign (%). If pid is not an active process ID, the wait utility returns immediately and the return code is 0. csh Wait for your background processes. ksh When an asynchronous list is started by the shell, the process ID of the last command in each element of the asynchronous list becomes known in the current shell execution environment. If the wait utility is invoked with no operands, it waits until all process IDs known to the invoking shell have terminated and exit with an exit status of 0. If one or more pid or jobid operands are specified that represent known process IDs (or jobids), the wait utility waits until all of them have terminated. If one or more pid or jobid operands are specified that represent unknown process IDs (or jobids), wait treats them as if they were known process IDs (or jobids) that exited with exit status 127. The exit status returned by the wait utility is the exit status of the process requested by the last pid or jobid operand. The known process IDs are applicable only for invocations of wait in the current shell execution environment. ksh93 wait with no operands, waits until all jobs known to the invoking shell have terminated. If one or more job operands are specified, wait waits until all of them have completed. Each job can be specified as one of the following: number number refers to a process ID. -number number refers to a process group ID. %number number refers to a job number %string Refers to a job whose name begins with string %?string Refers to a job whose name contains string %+ Refers to the current job %% %- Refers to the previous job If one ore more job operands is a process id or process group id not known by the current shell environment, wait treats each of them as if it were a process that exited with status 127. OPERANDS
The following operands are supported: pid The unsigned decimal integer process ID of a command, for which the utility is to wait for the termination. jobid A job control job ID that identifies a background process group to be waited for. The job control job ID notation is applicable only for invocations of wait in the current shell execution environment, and only on systems supporting the job control option. USAGE
On most implementations, wait is a shell built-in. If it is called in a subshell or separate utility execution environment, such as one of the following, (wait) nohup wait ... find . -exec wait ... ; it returns immediately because there is no known process IDs to wait for in those environments. EXAMPLES
Example 1 Using A Script To Identify The Termination Signal Although the exact value used when a process is terminated by a signal is unspecified, if it is known that a signal terminated a process, a script can still reliably figure out which signal is using kill, as shown by the following (/bin/ksh and /usr/xpg4/bin/sh): sleep 1000& pid=$! kill -kill $pid wait $pid echo $pid was terminated by a SIG$(kill -l $(($?-128))) signal. Example 2 Returning The Exit Status Of A Process If the following sequence of commands is run in less than 31 seconds (/bin/ksh and /usr/xpg4/bin/sh): sleep 257 | sleep 31 & jobs -l %% then either of the following commands returns the exit status of the second sleep in the pipeline: wait <pid of sleep 31> wait %% ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of wait: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
ksh93 The following exit values are returned by the wait built-in in ksh93: 0 wait was invoked with no operands. All processes known by the invoking process have terminated. 127 job is a process id or process group id that is unknown to the current shell environment. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |Standard |See standards(5). | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), jobs(1), ksh(1), ksh93(1), sh(1), attributes(5), environ(5), standards(5) SunOS 5.11 13 Mar 2008 wait(1)