Disown a job currently running under another shell - linux

At location A I started a process that will be running on a server over the night. I never disowned this process nor did I use nohup. =\
I am now at location B and I want to keep this process running but I want to kill the shell and logout at location A.
Is it possible to do what I want from location B?

You can try reptyr. But since neercs is not what you want, which can also grab processes from another shell, maybe reptyr does not help you, too.
Of course, after moving the application to your new shell, you need to kill the old one to logout.

You can give neercs a shot.
Here's a video showing how it works.
It's supposed to very unstable, though, and isn't packaged in CentOS or Debian-based distributions.

Related

How to know whether my program is being execute manually or by cron or from another script

My question is stated in the title:
How can I discover whether my program is being execute manually or by cron or from another script, and what account is being used?
I hope you guys can help me.
You can get the parent PID with getppid.
Then finding the parent process name from its PID is non-portable. On linux/unix you could run the ps command and parse the output. On Windows you'll probably need something like Win32::Process::List. No idea for OSX or other operating systems, try Googling perl get process name from pid.

Monitor multiple instances of same process

I'm trying to monitor multiple instances of the same process. I can't for the life of me do this without running into a problem.
All the examples I have seen so far on the internet involve me writing out the PID or monitoring the process itself. The issue is that if one instance fails, it doesn't mean all the rest have failed as well.
In order for me to write out the PID for each process it would mean I'd probably have to run each process with a short delay to record the correct, seeing as the way I need to record the PID is done through the process name being probed.
If I'm wrong on this, please correct me. But so far I haven't found a way to monitor each individual process, which all have the same name.
To add to the above, the processes are run in a batch script and each one is run in its own screen (ffmpeg would otherwise not be able to run in the background).
If anyone can point me vaguely in the right direction on how to do this in Linux I would really appreciate it. I read somewhere that it would be possible to set up symlinks which would then give me fake process names and that way I can monitor the 'fake' process name.
man wait. For example, in shell script:
wget "$url1" &
pid1=$!
wget "$url2" &
pid2=$!
wait $pid1 $pid2
will launch both wget processes, and wait until both processes are finished (or failed)

Scp as background job?

Here is the problem:
i must move some files from one host to another, ok i use scp for
it.
But i need use it without blocking console, so should use scp &. But my job will killed after disconnecting (a heard it`s something called hup signal) so i found some tricks for fixing this.
But i wanna see progress bar after some time and all that tricks couldnt work because when i use jobs - it display jobs that only for these session.
So how to fix my problem ?
P.S. Sorry for my English.
I am not sure it is what you want but I'll suggest GNU Screen. It allows you to run a program so that when you log out, the program continues execution in the background. Later you can log back in and resume interaction with the program.
I guess you want ability to detach -and- attach terminal - The tool is called screen.

How can I know that a cron job has started or finished?

I have put a long running python program in a cron job on a server, so that I can turn off my computer without interrupting the job.
Now I would like to know if the job is correctly started, if it has finished, if there are reasons to stop at a certain point, and so on. How can I do that ?
You could have it write to a logfile, but as it sounds like this isn't possible, you could probably have cron email you the output of the job, try adding MAILTO=you#example.com to your crontab. You should also find evidence of cron activity in your system logfiles (try grep cron /var/log/* to find likely logs on your system).
If you are using cron simply as a way to run processes after you disconnect from a server, consider using screen:
type screen and press return
set your script running
type Ctrl+A Ctrl+D to detatch from the screen
The process continues running even if you log off. Later on simply
screen -r
And you will be will reattached, allowing you to review the script's output
Why not get that cron job to have a log file. Also just do a ps before shutdown.

Linux - communicating with a process? rejoin process in action?

I feel somewhat dumb asking this, but I'm relatively new to linux (more in terms of experience than time), and one thing that i've always wondered is if I can 'rejoin' (my own term) a process while it's running.
For example, if I set a game server or eggdrop IRC bot to run in the background, is there a command I can use to view that process in action and view all the output it delivers to the console?
I'm not talking about just viewing the process using the 'top' command, but actually linking to it as if I just ran it from the command line.
Thanks.
Debuggers can "attach" to running processes, but you might be better running your program in screen (which lets you detach and reattach to terminal in a fairly natural way).
There might be some good stuff good stuff in :
Redirect STDERR / STDOUT of a process AFTER it’s been started, using command line?
Can you be more specific? Are you just talking about backgrounding a process in the current session, then putting it back in the foreground.
E.g.:
doLongTask &
# Later
fg %3
3 in this example is the job number of this instance of doLongTask. You can see all running jobs with:
jobs
But note this will still only let you see what's being outputted to the console. I.E. stdout and stderr, minus any redirections.
The simple answer is:
>> ./runmyserver
<press ctrl-z>
>> bg
>> ...do something else ...
>> fg
You can also start in the background with:
>> ./runmyserver &
For more complicated stuff like disconnecting the server from your console session (so it's still running when you log out) you really want screen. Maybe beg them for it, it isn't really a security risk and it's a useful program to have around.
Also note that ctrl-z will actually pause your server until bg so if people are playing on it might skip a beat, best to do it quickly.
Finally, many game servers have a remote login for this kind of thing which would solve many of these issues. Make sure your game and host don't support this before looking for alternatives.
EDIT: Re-read your question. It sounds like you could at least get the output using redirect to a file. This won't let you add more input though:
./runmyserver > log.txt
If you know ahead of time that you want to do this, use screen(1) and run your server in the foreground in a screen session. You will be able to detach from your screen session and have the process keep running. You can then later re-attach your screen session and view any output it has made since, up to the size of the scrollback buffer.

Resources