7

I have multiple serial ports to each of which devices are connected. They are listed as /dev/ttyUSB*. Now, I need to make sure using a python script that no other process is using any of these before I run a kermit script (so that access is not denied) login_init. I tried ps and lsof commands. lsof gave the following output:

sof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
  Output information may be incomplete.
COMMAND     PID        USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
login_ini 13395       user4    4u   CHR  188,9      0t0  512 /dev/ttyUSB9
python    14410       user4    6u   CHR  188,9      0t0  512 /dev/ttyUSB9

I got the pids of the processes alright, but when I give the killall command, it says no process found as follows:

user4@user-pc-4:~/Scripts$ killall -9 13395
13395: no process found

user4@user-pc-4:~/Scripts$ killall -9 14410
13395: no process found

Is this the right and the only way or there are better ways to do it?

12

killall expects a substring of the program's name as argument. To kill a process by its process ID, use kill.

You can directly kill all the processes that have a file open with the command fuser.

fuser -k /dev/ttyUSB9
1
  • @TimKennedy I don't recommend the use of killall at all — it's the wrong tool for this job anyway. This question is clearly about a Linux system, so warnings about Solaris which most readers of this thread will never use are not useful here. Apr 5 '17 at 1:50
1

Since you already have the process ID's, you can just use kill, i.e.

kill -TERM 13395 14410 

(I would suggest sending a normal SIGTERM first, before pushing the SIGKILL-button.)

The killall command used in Linux systems kills process by name, as does pkill. However, on other systems, such as Solaris, killall kills everything (as part of the shutdown procedure), which might be good to keep in mind if you ever use those.

1

Use below commands to kill pid

sudo kill -9 13395

sudo kill -9 14410

if you want to kill all(/dev/ttyUSB9) in a single command then use below command

sudo pkill -9 ttyUSB9

To list the running process id.then use below command

ps -ef | grep ttyUSB9

To list the number of running process id.then, use below commands

ps -ef | grep ttyUSB9 | wc -l

0

I solved following serial port related problems in ubuntu 18.04 as follows:

Problem 1 : Cannot open /dev/ttyACM0: Permission denied
Solution : Grant permissions to read/write to the serial port with this terminal command ---> sudo chmod a+rw /dev/ttyACM0 Here replace tty port with your respective ubuntu port.

Problem 2 : Failed to open /dev/ttyACM0 (port busy) Solution : This problem appears when serial port is busy or already occupied. So kill the busy serial port with command ---> fuser -k /dev/ttyACM0. Here replace tty port with your respective ubuntu port.

Problem 3 : Board at /dev/ttyACM0 is not available Solution : In this case your serial port in tools menu will be greyed out. I googled a lot for this, but I none of solution worked for me. Atlast I tried different arduino board and usb connector and it was working for me. So, if you are having old arduino board (can be solved using required drivers) or defected arduino board then only this problem arises.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.