Hi I just started using ps. So, I am trying to run a R script in a cluster (after logging in using ssh) by writing
nohup R CMD BATCH a.R > a.out &
Then when I use ps -u myusername it shows :
PID TTY TIME CMD
4200 pts/14 00:00:00 ps
29985 ? 00:00:00 sshd
29986 pts/14 00:00:00 tcsh
32146 pts/14 00:00:00 sh
32150 pts/14 01:10:10 R
Now when I log in into ssh from new terminal window and do the same ps -u myusernameit shows
PID TTY TIME CMD
444 ? 00:00:00 sshd
445 pts/1 00:00:00 tcsh
2460 pts/1 00:00:00 ps
It doesn't show the R job I started in other terminal window. How can I see that? And even if I close the first terminal/log out from ssh, the R script should still be running, right? Because of the nohup. Sorry for so many basic question. I never used nohup and ps before, and all the details are making me feel lost.
Try
top -u myusername
If you still don't see your job, the job is not running.
I personally had the same issue but somehow with the command
nohup R --vanilla < mycode.R >& mycode.Rout&
worked.
Related
I am running the below shell script to run in background ./something.sh &
#!/bin/bash
tail -n0 -f -F service.log | while read LOGLINE
do
done
when i check ps -ef| grep something, i see two processes
20273 1 0 16:13 ? 00:00:00 /bin/bash /something.sh
20280 20273 0 16:13 ? 00:00:00 /bin/bash /something.sh
This is because your script is piping the output of a program to a shell command. When you run this there will be three processes:
The something.sh that you explicitly started
The tail that your script starts
A copy of something.sh that is executing the while loop.
I created a new session of tmux, intending to use the -s flag to name it, but confused the command with -S which specifies a socket. I know the session is alive, because the processes I started in it are still running. But when I try to list running sessions it does not appear. Where is my session and how do I recover it?
In tmux option -S means socket path (from man tmux):
-S socket-path
Specify a full alternative path to the server socket. If -S is specified, the default
socket directory is not used and any -L flag is ignored.
So you have to find out the parent directory where tmux was run with
-S option and pass this option to tmux to point it to the
alternative socket path. You could for example find PID of the
tmux process:
$ ps aux | grep '[t]mux'
ja 15121 0.0 0.0 20252 2236 pts/6 S+ 00:44 0:00 tmux -S new
And then check this process cwd in /proc like this:
$ ls -l /proc/15121/cwd
lrwxrwxrwx 1 ja users 0 Aug 19 00:52 /proc/15121/cwd -> /home/ja
And then to refer to this tmux session:
$ tmux -S /home/ja/new ls
0: 1 windows (created Sat Aug 19 00:44:46 2017) [212x65] (attached)
Can anyone suggest how I might get this working....
I have an R script that takes several minutes to run and writes a few hundred lines of output. I want to write a shell script wrapper around this R script which will launch the R script in the background, pipe its output to a file and start following the bottom of that file. If the user then enters CTRL-C I want that to kill the shell script and tail command but not the R script. Sounds simple right?
I've produced a simplified example below, but I don't understand why this doesn't work. Whenever I kill the shell script the R script is also killed despite apparently running in the background. I've tried nohup, disown etc with no success.
example.R
for(i in 1:1000){
Sys.sleep(1)
print(i)
}
wrapper.sh
#!/bin/bash
Rscript example.R > logfile &
tail -f logfile
Thanks in advance!
The following seems to work on my Ubuntu machine:
#!/bin/bash
setsid Rscript example.R > logfile.txt &
tail -f logfile.txt
Here are some of the relevant processes before sending SIGINT to wrapper.sh:
5361 pts/10 00:00:00 bash
6994 ? 00:00:02 update-notifier
8519 pts/4 00:00:00 wrapper.sh
8520 ? 00:00:00 R
8521 pts/4 00:00:00 tail
and after Ctrl+C, you can see that R is still running, but wrapper.sh and tail have been killed:
5361 pts/10 00:00:00 bash
6994 ? 00:00:02 update-notifier
8520 ? 00:00:00 R
Although appending your Rscript [...] command with & will send it to the background, it is still part of the same process group, and therefore receives SIGINT as well.
I'm not sure if it was your intention, but since you are calling tail -f, if not interrupted with Ctrl+c, your shell that is running wrapper.sh will continue to hang even after the R process completes. If you want to avoid this, the following should work,
#!/bin/bash
setsid Rscript example.R > logfile.txt &
tail --pid="$!" -f logfile.txt
where "$!" is the process id of the last background process executed (the Rscript [...] call).
this question relates to close connection and perhaps also to this close Rserve. However, in the later case there are connections open and in the first case the answer does not specify how to "kill" the server.
It is important to say that I am new to Rserve, and I have used it for the 1st time today for some mild R-python interaction. I started Rserve from the command line as:
% R CMD RServe
I though I had closed the connection after the session, but when I now try to re-start Rserve again with a new configuration I get the error:
% ##> SOCK_ERROR: bind error #48(address already in use)
which is pretty clear. Moreover ps ax | grep Rserve returns:
% ps ax | grep Rserve
18177 ?? Ss 0:00.33 /Library/Frameworks/R.framework/Resources/bin/Rserve
18634 s006 U+ 0:00.00 grep Rserve
which I understand that indeed means that the server is running. I have tried a few things:
% R CMD RSclose
/Library/Frameworks/R.framework/Resources/bin/Rcmd: line 62: exec: RSclose: not found
% R CMD RSshutdown
/Library/Frameworks/R.framework/Resources/bin/Rcmd: line 62: exec: RSshutdown: not found
and finally
% R CMD shutdown
shutdown: NOT super-user
I am wondering, should I then run:
% sudo R CMD shutdown
(I would like to make sure before running that command, in case I screw something)
Anyway, the question would be very simple. How can I close server to re-run it.
Thanks in advance for your time!
You are confused:
R CMD something
will always go to R. And R no longer knows Rserve is running even though you may have started it via R CMD Rserve: these are now distinct processes.
What you should do is
kill 18177 # or possibly kill -9 18177
and there are wrappers to kill which first grep for the name and find the PID for you:
killall Rserve # or possibly killall -9 Rserve
The -9 sends a higher-order SIGKILL (ie 'really go and die now') intensity than the default of -15 for SIGTERM) (ie 'please stop now').
I know that I can run tmux -V to find the version of tmux that is in my PATH, but how can I get the version of tmux that is currently running?
As pointed out in a comment, tmux -V returns the version:
$ tmux -V
tmux 3.0a
Tested on Centos 7 and OSX 12.5.
Most obvious, but not 100% correct way is to execute this command in console
$ tmux -V
and receive output like this tmux 2.9a with version of tmux INSTALLED, not currently running.
In 99% cases it is enough, but there can be subtle nuances.
Command tmux -V will return version of tmux installed at /usr/bin/tmux or any other directory inside your PATH variable. If you have tmux already running, it is possible that tmux can be started from binary of other version and from different place (for example, tmux can be started from /home/user/bin/tmux).
In this case, you have to call
$ ps -e | grep tmux
to see PID of all tmux processes currently running. It will output something like this
[vodolaz095#ivory ~]$ ps -e | grep tmux
19699 pts/0 00:00:00 tmux: client
19701 ? 00:00:00 tmux: server
Here, number 19701 depicts process id (PID) of currently running tmux server.
After getting PID of tmux server, you can ran command
$ lsof -p 19701
to get information about CURRENTLY RUNNING tmux server process (in my case its 19701) that will output something like this (Figure 1)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
tmux:\x20 19701 vodolaz095 cwd DIR 8,33 4096 22544385 /home/vodolaz095
tmux:\x20 19701 vodolaz095 rtd DIR 8,1 4096 2 /
tmux:\x20 19701 vodolaz095 txt REG 8,1 677760 3675332 /usr/bin/tmux
tmux:\x20 19701 vodolaz095 mem REG 8,1 6406312 131327 /var/lib/sss/mc/group
as you can see, tmux currently running was executed from binary placed in /usr/bin/tmux.
Or, you can call one liner
lsof -p `pgrep 'tmux: server'`
to achieve the same output as Figure 1
After you get path to tmux binary CURRENTLY RUNNING, (in my case, it was /usr/bin/tmux), you can execute this binary with flag -V to get its version
/usr/bin/tmux -V
or, if tmux was installed by limited user into /home/user/bin/tmux,
/home/user/bin/tmux -V
And, as result, you'll get version of tmux currently running, not the one, that was installed.
To get the version of the tmux server you can use display-message.
./tmux2.3 display-message -p "#{version}"
Will show the version of the server (2.7 in my case)
-p will direct the output of stdout so you can script with it and {version} can be anything from the FORMATS section in the man page.
The following will give you the executable of your tmux server, on linux:
realpath /proc/$(tmux display-message -p "#{pid}")/exe
And on macos, proc_pidpath can be used, see https://stackoverflow.com/a/8149380
To find the actual version of the tmux that is running, you have to find the PID of the tmux:
pgrep tmux
With this info, you can check the version by running:
lsof -p $tmuxPID | grep REG | grep -i -e deleted -e "tmux$"
If there is not a (deleted) next to the tmux file listed, you can just run that file with a -V.
If it results in files that are "(deleted)", you are running an old, uninstalled version. If you are on linux, you can figure out what it is by running:
/proc/$tmuxPID/exe -V`
If you are on OS X, you are stuck with whatever information is in the path to the filename, possibly something like Cellar/tmux/<version number>/bin/tmux.
You can combine many of these steps into the following one-liner:
for tmuxPID in $(pgrep tmux); do lsof -p $tmuxPID | grep REG | grep -i -e deleted -e "tmux$"; done
Or if you are on Linux, this always works:
for tmuxPID in $(pgrep tmux); do /proc/$tmuxPID/exe -V; done