i want to control the TTYs (serial port )used by applications on my pc.
there is an applications that shows the status of each port by indicating the processes which are using?
Thanks a lot!
Try to use the command lsof.
lsof /dev/ttyX
To get the PID directly, use:
lsof -Fp /dev/ttyX
Related
I launch Stanford Core NLP server using the following command (on Ubuntu 16.04):
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
I would like to kill this server once I am done using it. Simply closing terminal does not help. It does not release memory. Is there way to kill it and release memory without rebooting computer?
You can always CTRL-C in the terminal window to stop the server.
You could also ps aux | grep StanfordCoreNLPServer to find the pid and then kill the process manually.
When the server is started it should create a shutdown key and you can send that message to the server to close the server. This isn't working on my Macbook Pro (maybe a permission issue ??) but I've seen it work on other machines.
Here is the command:
wget "localhost:9000/shutdown?key=`cat /tmp/corenlp.shutdown`" -O -
Note the shutdown key is stored at /tmp/corenlp.shutdown
If you use the the -server_id server0 option the shutdown key will be stored at this path /tmp/corenlp.shutdown.server0
If you just want to kill the process. You can use lsof command.
#install lsof if missing
sudo apt install lsof
You can find the pid of CoreNLP using
lsof -i:9000
Replace 9000 with the port you used to run the server.
The output looks like
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 15867 XXXX XXX IPv6 XXXXXX 0t0 TCP *:9000 (LISTEN)
Use the pid from here and run.
kill 15867
PID of my server process is 15867.
Is there an auditing tool to check which and when ports are opened and closed on Linux?
My goal is to run my application and check its ports usage.
lsof or netstat don't fit because they just tell me which ports are currently opened, and looping on such command won't give me accurate results...
strace -f -e trace=bind mvn install
strace will displays the bind sytem call each time my application an the children processes open a port.
How can you find out which process is listening upon which port on Windows and Linux?
Are there some Applications explicitly monitoring?
Some great tools for this are made by Sysinternals, now owned by Microsoft.
The one you want is Tcpview and it will show you the ports and which application has them opened, as well as the PID and other nice things. Tcpview is windows based but they have a command line version as well. All these tools are free.
This is the link Microsoft's sysinternals downloads
Both Windows and Linux has the netstat-command built-in, although they are used differently.
On Windows: netstat -a -b (lists both listening and connected ports)
On Linux: netstat -l -p (lists only listening ports)
On windows 7, you can use
netstat -b -a
netstat /?
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-o Displays the owning process ID associated with each connection.
On Linux use, -p needs root privileges.
#netstat -p
#netstat -h
-p, --programs display PID/Program name for sockets
Not sure that stackoverflow is the right place for this question, maybe http://www.superuser.com would be a better choice.
Although from the top of my head:
Linux has lsof and netstat commands that will provide this information.
Windows has ProcessExplorer that should give this information.
In Linux you can use the ss command to dump the socket information. It gives information about active port numbers in the client side also. More details can be found here
http://linux.die.net/man/8/ss
I'm trying to use fuser to find the pids of processes I own which have certain TCP ports open.
In the fuser man page it says:
... The most common time this problem occurs is when looking for TCP or UDP sockets when running fuser as a non-root user. In this case fuser will report no access. ...
However, on my Ubuntu box, fuser does report sockets open for processes that I own, e.g.:
perl -MIO::Socket 'IO::Socket::INET->new(Listen => 10, LocalPort => 3000)' &
fuser -n tcp 3000
Question: how are things set up to allow this to happen? Is it a kernel config option?
Thanks!
Note: the question is: how are some linux distros configured so that fuser will report processes owning sockets when fuser is run as a normal user? One one Ubuntu distro "fuser -n tcp 3000" will report a process if I own the process, yet on another linux distro (I think Centos) it won't report the process even if I own it.
fuser goes through the /proc file system (proc(5)) working through the /proc/[pid]/fd/ directory and checking the file descriptors. Processes owned by you have corresponding /proc entries again owned by you. This allows you to check your processes, but not others.
One very useful tool to see what given program is doing is strace(1). For example, you can see what system calls, and with what arguments, are done by the fuser:
~$ strace fuser -n tcp 3000
Can I see PID who uses COM1 in Debian from start os and if can how ?
Is there any log file for this ?
The simple way is to simply:
$ fuser /dev/ttyS0
Note that this will only show processes from your own user, unless you're root.
The kernel does not directly log when processes open the serial port. There are a number of options if you need to log:
Periodically log the output of fuser /dev/ttyS0 or lsof /dev/ttyS0.
Restrict access to /dev/ttyS0 to a special-purpose user, and use sudo or some other gateway program to gain access to it. This will leave logs when the gateway program is invoked.