Note that you could still improve it, for instance, by excluding kernel threads (which aren't processes). And there you go! This final line gives you all non-GUI processes running without a controlling terminal. kill command sends a signal to the process. Stop a process To stop a process in Linux, use the ' kill’ command. ps -A This command lists even those processes that are currently not running. The final grep captures all lines which begin with "?", that is, all processes without a controlling tty. While ps command only displays the processes that are currently running, you can also use it to list all the processes. For this, I'll add -o tty,args to the previous line in order to output the tty of each process (and its full command line) : $ ps -C "$(xlsclients | cut -d' ' -f3 | paste -s -d ',')" -deselect -o tty,args | grep ^? Let's not forget our "no TTY attached" rule. Now, we have a list of all non-GUI processes. $ ps -C "$(xlsclients | cut -d' ' -f3 | paste -s -d ',')" -deselect Note that I'm using -deselect afterwards to reverse my selection. We just got our command list, so let's inject it into the ps command line. Now, ps has a -C switch which allows us to select by command name. $ xlsclients | cut -d' ' -f3 | paste -s -d ',' From the answer I just linked, this is done using. This can be done using the -deselect switch.įirst, we'll build a list of all GUI programs for which we have running processes. Luckily for us, there is a program to list GUI processes : xlsclients! This answer from slm tells us how to use it to list all GUI programs, but we'll have to reverse it, since we want to exclude them. Note that daemons which start at boot time are usually running as root.īasically, we would like to display all programs without a controlling terminal, but not GUI programs. Daemons running without root privileges won't.If root is running graphical programs, they will show up.This can be achieved using ps' -U switch. On a standard system, where root does not run graphical programs, you could simply restrict the previous list to root's processes. Chromium) are not attached to a terminal, they also appear in the output. The big problem here comes when your system runs a graphical environment. The tty output field contains "?" when the process has no controlling terminal. This can be done quite easily with ps: $ ps -eo 'tty,pid,comm' | grep ^? Now, if we use the information that I gave in my answer, we could find running daemons by searching for processes which run without a controlling terminal attached to them. Just to make the notion a little clearer : a program is an executable file (visible in the output of ls) a process is an instance of that program (visible in the output of ps). For this reason, there is no sense in "finding daemons on the filesystem". The notion of daemon is attached to processes, not files.
0 Comments
Leave a Reply. |