linux - command line to get version of terminal - linux

I use a terminal which I don't know the name. By which command can I find the name and version of that?
(I use android operating system)

echo $TERM tells you kind of terminal you are using, eg. xterm

Use the ps command with no arguments to get the processes running under the current shell.
Example:
% ps
PID TTY TIME CMD
1917 pts/0 00:00:00 zsh
13659 pts/0 00:00:00 ps

Related

WSL, Running linux commands with "wsl --exec <cmd>" or "wsl -- <cmd>"

wsl -h shows the following:
--exec, -e <CommandLine> Execute the specified command without using the default Linux shell.
-- Pass the remaining command line as is.
What does "without using the default Linux shell" mean (i.e. what else is it going to use, if not the default shell!?)?.
Additionally, by way of an example, I now have three possible ways to run Linux ls from my PowerShell prompt (i.e. this will not be Get-ChildItem aliased to ls, but instead a Linux command via WSL):
PS C:\> wsl -e ls # Alternatively, wsl --exec ls
PS C:\> wsl -- ls
PS C:\> wsl ls
But all outputs appear to be the same. How would you explain the differences between these three ways of running a WSL Linux command from a PowerShell prompt?
I think it means wsl runs the command directly, instead of spawning a shell process to run the command.
For example, if I run :
wsl -e sleep 10
From another terminal, I have :
root 1482 1 0 11:32 tty3 00:00:00 /init
ubuntu 1483 1482 0 11:32 tty3 00:00:00 sleep 10
We can see /init is the parent of sleep 10, without a shell in between.
A cool trick is using this to set the X11 $DISPLAY variable, letting you use windows terminal to get remote shells using WSLG.
# in microsoft terminal or powershell use this command line
wsl.exe -- ssh -a -X -Y $hostname
then on the remote system
# DISPLAY will show something like localhost:10.0 on the remote system
echo $DISPLAY
# use a program like xeyes to test
xeyes

How to distinguish between two running Linux scripts with the same name?

I use SSH to connect to Linux, maybe run a Linux script multiple times, and use nohup to suspend these processes, and then close the SSH connection. After the next SSH connection to Linux, how can I distinguish between different scripts and get different PIDs?
This Linux script will always print content on the screen. I use Python's paramiko library, SSH to Linux, run the script and use nohup to suspend the process and redirect the output to the file. This process may be multiple times. How to distinguish the starting process, find its PID and kill it. It is best not to modify the Linux script because the script is not written by me.
I use the script name to find the process number, get a lot of PIDs, I can't distinguish them.
You could parse the output of ps -eo pid,lstart,cmd which shows the process id, start time and path, e.g.:
PID STARTED CMD
1 Mon Jun 19 21:31:08 2017 /sbin/init
2 Mon Jun 19 21:31:08 2017 [kthreadd]
3 Mon Jun 19 21:31:08 2017 [ksoftirqd/0]
== Edit ==
Be aware that if the remote is macOS the ps command does not recognize the cmd keyword, use comm or command instead, e.g.: ps -eo pid,lstart,comm
Use ps command to check running process.
For checking only shell scripts , You an do something like this:-
ps -eaf |grep .sh
This will give you all the information about running shell scripts only, easily you can distinguish b/w running scripts.
In place of ".sh" you can give file name also, than you will get information only about that running file.
maybe change the command you run to do something like:
nohup command.sh &
echo "$! `date`" >> runlog.txt
wait
i.e. run the command in the background, append its PID to a log (you might want to include more identifying information here or use a format that's more easily machine readable), then wait for it to finish
another variant would be to run tmux (GNU screen) on the server and run commands in an existing session:
tmux new-window command
which would also let you "reconnect" to running scripts later to check output / terminate

package Shell: System commands doesn't work with Centos 7.4

Shell module, Shell.pm, does not seem to run shell commands with Centos 7.4.
For instance following script is OK with Centos 6.4:
#!/usr/bin/perl
use Shell qw(ps);
$cmd=ps;
print $cmd . "\n";
Result is as expected:
PID TTY TIME CMD
29090 pts/1 00:00:00 bash
29325 pts/1 00:00:00 test.pm
29326 pts/1 00:00:00 ps
But with Centos 7.4
#!/usr/bin/perl -I /usr/share/perl5/CPAN
use Shell qw(ps);
$cmd=ps;
print $cmd . "\n";
Result is:
ps
If i add to the previous script:
cat("/etc/passwd");
Following error is raised:
Undefined subroutine &main::cat called at ./test.pm line 10
With a real script none of system commands are well interpreted. Should I rewrite everything with system('command')!?
Finally I succeeded to make it work !
Installation was not quite good.
I had to run :
cpan App::cpanminus
then
cpanm Shell

getting the pid of a process in zsh

I am coding on a Red Hat Machine and I want to get the process id of a process in the interactive mode as well as the in a script.
In bash 'pidof' works but not in zsh.
What would be the equivalent of pidof in zsh ?
Thank you in advance.
You may wish to which pidof in bash, to determine the location of pidof and then try running zsh with the absolute path.
If the above works, you just have a $PATH issue (as I have never seen pidof as a bash builtin.)
If that doesn't work try the following:
This is probably not a simple as you want, but it works for me:
pgrep -U $USER some_program
Where 'some_program' is the name you would normally supply pidof.
On a RHEL (Red Hat Enterprise Linux) machine pidof is located at /sbin/pidof. Just add /sbin to your path.

get a bash's cwd

If I open up 2 terminals in Ubuntu, via ps u I can see 2 bash's pid.
My problem is from one terminal, how can I know the bash's cwd in the other terminal?
You can check
/proc/<pid>/cwd
The pwdx command prints the current working directory of each given process ID.
Example from Solaris (believe Ubuntu also has the command):-
$ cd /tmp
$ pwdx $$
22281: /tmp

Resources