M
M
Maxim Ivanov2016-12-07 13:19:18
linux
Maxim Ivanov, 2016-12-07 13:19:18

How to kill a process that I can't get pid on unix?

In the program for reading data from a device via usb, I read the data in this way, I just redirect the stream to a file

[email protected]:$ stty 4800 -F /dev/ttyUSB0  && cat /dev/ttyUSB0 > stream/tty.txt

all data is constantly written to tty.txt files, and if I execute the command above, then through the terminal I can’t disable it in any way via ctrl+z/ctrl+c and others. The bottom line is that users will not use the terminal at all, I have to kill the process with my program.
the trouble is that my program in a separate thread has to run this command so that in another thread I can read data from the tty.txt file,
but the file is constantly growing and can reach large sizes, I would like to make it so that I can at any time run above command and kill those commands with kill
but when in terminal i run (all as root):
[email protected]:$ ps aux
splinco+ 18157  0.3  1.2 871608 92860 ?        Sl   12:47   0:05 /opt/google/chrome/chrome --type=renderer --enable-features=*AutofillCreditCardSigninPromo<AutofillCred
root     18315  0.1  0.0      0     0 ?        S    12:51   0:01 [kworker/u8:1]
root     18397  0.0  0.0      0     0 ?        S    12:54   0:00 [kworker/3:0]
root     18457  0.0  0.4 942988 30888 pts/1    Sl+  12:56   0:00 node server.js
root     18463  0.0  0.0   4476   760 pts/1    S+   12:56   0:00 /bin/sh -c  ??stty 4800 -F /dev/ttyUSB0  && cat /dev/ttyUSB0 > stream/tty.txt         
root     18465  0.0  0.0  12800   668 pts/1    S+   12:56   0:00 cat /dev/ttyUSB0
root     18466  0.1  0.0      0     0 ?        S    12:56   0:01 [kworker/u8:0]
root     18492  0.0  0.0      0     0 ?        S    12:56   0:00 [kworker/2:1]



[email protected]:$ ps aux | grep stty
root     18463  0.0  0.0   4476   760 pts/1    S+   12:56   0:00 /bin/sh -c  ??stty 4800 -F /dev/ttyUSB0  && cat /dev/ttyUSB0 > stream/tty.txt

[email protected]:$ pidof stty # ничего не выводит

But the process must be killed somehow, and I don’t know how
the process itself is really killed if you pull out the usb cord and insert it back, but I can’t have such an opportunity, for those people who will use the program.
Maybe there is an emulation of usb shutdown and turning it back on for /dev/ttyUSB0 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-12-07
@splincodewd

stackoverflow.com/questions/1323956/how-to-redirec...
потому что нужно грепать cat, отфильтровать результат грепа, взять второй столбик
cat /dev/urandom > /dev/null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question