Process Id of Chomium-browser not showing in terminal - linux

I am writing a bash script and I need to kill any browser running at the time of script execution. For that I want the process id of every browser running in the background. I tried all the following, but nothing worked. See this
pidof chromium
pidof chromium-browser
pgrep chromium-browser
ps -A | grep chromium-browser
ps -aux | grep chromium-browser | grep pid
However, See this . It worked for firefox browser. Can Anyone figure out If it's something wrong with command or Chromium-browser itself. Also Can anyone tell any other method to get the process id. I shall try that out by the time.

You can try the following piece of script to list all pids of processes containing chromium-browser in their command name :
ps -aux | grep chromium-browser | tr -s ' ' | cut -d ' ' -f 2
Your other commands didn't work because the process running for chromium-browser is /usr/lib/chromium-browser/chromium-browser (at least for me on xubuntu). You can check the real process by typing ps -aux.
Note: weirdly enough, pgrep chromium-browser doesn't return anything, but pgrep chromium and pgrep chromium-browse work just fine.
pgrep -f chromium-browser is also good

Have similar issue. The reason for this is that executable file named chrome. (I'm using chromium via snap on Ubuntu 18.04)
/snap/chromium/861/usr/lib/chromium-browser/chrome --type=renderer --field-trial-handle=17044127674507841828,2715256006050366173,131072 --lang=en-US --extension-process --enable-auto-reload --num-raster-threads=4 --enable-main-frame-before-activation --service-request-channel-token=10676003778996199464 --renderer-client-id=7 --no-v8-untrusted-code-mitigations --shared-files=v8_context_snapshot_data:100,v8_natives_data:101
So, use chrome for you query.
Or if you'd like to use chromium-browser you need to use additional match options, like pgrep -f.

Related

centos | perl processes are not shown

I have a centos server in which I have install perl package to run some perl scripts. today I run some perl scripts, and when I run ps -ef | grep perl it shows nothing although the scripts are working properly.
When I use pkill -f (name_of_script) the perl process stopped however they are not shown at all.
Note that yesterday I deleted a user ( X ) which was affected to folder /home/scripts. What do you think the problem is from?
The reason for not showing the process in ps -ef might be due to the process being run as a background process. In that case, the process won't be associated with the terminal where you started it from and thus won't be shown in the output of ps -ef. To see all processes running on the system, including background processes, you can use ps aux instead.

How to kill program running in background in ubuntu?

I'm working on MINI2440 and building a custom OS for it using buildroot, but for testing purpose I'm using OS downloaded from official website.
So the problem is, I'm using usbpush to push OS images in MINI2440 through USB, but it popups the message when I enter below commond
sudo ./usbpush supervivi-128M 0x30008000
Unable to claim usb interface 1 of device: could not claim interface 0: Device or resource busy
I don't understand one concept that, whenever I assign executable permission to usbpush, it runs automatically in background. It's clearly seen below
ps -ef | grep usb*
silicod+ 2431 2207 0 10:25 pts/10 00:00:00 grep --color=auto usbpush
I tried to kill using
sudo kill -9 2431
But it creates new pid and again run itsellf in background. I tried googling but nothing works for me.
=============================================================
Well, I got my solution. I don't know what is the problem with my usbpush tool, but I downloaded another tool and it works very well. Here is the link to that tool , may it help someone
Friendly_ARM_Mini2440_USBPUSH
Cheers....!
lovely ;-)
well I guess it is actually not running..
ps -ef will give you details about all running processes
grep usb* - (loose the *) will find any lines containing usb
the way unix/linux does it is that grep gets started first and then the "|" connects output of ps -ef to grep's input
so what you are finding is the grep command itself
what you want is ps -ef | grep -v grep | grep usb - this will work unless your "usb" command is something like grepusb or usbgrep or the line contains grep..

Linux bash script that kills a process (not started by me) after x amount of time

I'm pretty inexperienced with Linux bash. That being said, I have a CentOS7 machine that runs a COTS application server. This application server runs other processes that sometimes hang. Since I have no control over the start of these processes, I'm looking for a script that runs every 2 minutes that kills processes of the name "spicer" that have been running for longer than 10 minutes. I've looked around and have only been able to find answers for processes that are run and owned by me.
I use the command ps -eo pid, command,etime | grep spicer to get all the spicer processes. The output of this command looks like:
18216 spicer -l/opt/otmm-10.5/Spi 14:20
18415 spicer -l/opt/otmm-10.5/Spi 11:49
etc...
18588 grep --color=auto spicer
I don't know if there's a way to parse this directly in bash. I'm also not well-versed at all in other Linux tools. I know that awk (or gawk) could possibly help.
EDIT
I have no control over the data that the process is working on.
What about wrapping the executable of spicer and start it using the timeout command? Let's say it is installed in /usr/bin/spicer. Then issue:
cp /usr/bin/spicer{,.orig}
echo '#!/bin/bash' > /usr/bin/spicer
echo 'timeout 10m spicer.orig "$#"' >> /usr/bin/spicer
Another approach would be to create a cronjob defintion into /etc/cron.d/kill_spicer. Like this:
* * * * * root kill $(ps --no-headers -C spicer -o pid,etimes | awk '$2>=600{print $1}')
The cronjob will get executed minutely and uses ps to obtain a list of spicer processes that run longer than 10minutes and passes them to kill.
Probably you even want kill -9 if the process is hanging.
You can use the -C option of ps to select processes by name.
ps --no-headers -C spicer -o pid,etime
Then you can use cut to filter the results, if the spacing is consistent. On my system the pid field takes up 8 characters, so I'd use
kill $(ps --no-headers -C spicer -o pid,etime | cut -c-8)
If the spacing is inconsistent (but if so, what kind of messed up ps are you using? :-P), you can use awk { print $1 } instead of cut.

Bash script commands not running

I have seafile (http://www.seafile.com/en/home/) running on my NAS and I set up a cron tab that runs a script every few minutes to check if the seafile server is up, and if not, it will start it
The script looks like this:
#!/bin/bash
# exit if process is running
if ps aux | grep "[s]eafile" > /dev/null
then exit
else
# restart process
/home/simon/seafile/seafile-server-latest/seafile.sh start
/home/simon/seafile/seafile-server-latest/seahub.sh start-fastcgi
fi
running /home/simon/seafile/seafile-server-latest/seafile.sh start and /home/simon/seafile/seafile-server-latest/seahub.sh start-fastcgi individually/manually works without a problem, but when I try to manually run this script file, neither of those lines execute and seafile/seahub do not start
Is there an error in my script that is preventing execution of those 2 lines? I've made sure to chmod the script file to 755
The problem is likely that when you pipe commands into one another, you don't guarentee that the second command doesn't start before the first (it can start, but not do anything while it waits for input). For example:
oj#ironhide:~$ ps -ef | grep foo
oj 8227 8207 0 13:54 pts/1 00:00:00 grep foo
There is no process containing the word "foo" running on my machine, but the grep that I'm piping ps to appears in the process list that ps produces.
You could try using pgrep instead, which is pretty much designed for this sort of thing:
if pgrep "[s]eafile"
Or you could add another pipe to filter out results that include grep:
ps aux | grep "[s]eafile" | grep -v grep
If the name of this script matches the regex [s]eafile it will trivially always take the exit branch.
You should probably be using pidof in preference of reinventing the yak shed anyway.
turns out the script itself was working ok, although the change to using pgrep is much nicer. the problem was actually in the crontab (didn't include the sh in the command)

How to know if the process is set NOHUP?

Using jobs I know the process is running.
bash-4.2$ jobs
[1]+ Running test.sh &
I wanted it to be set NOHUP so that it won't be killed when I exit. I used
disown
and
bash-4.2$ jobs
shows nothing. I'm not sure if the process is set NOHUP or not. I'm curious about this because after I read the manual it says
disown -h
should be used to set NOHUP.
Edit
I don't think the link Find the Process run by nohup command helps. The question is different than that one.
I'm gonna restate my problem. I run a program without nohup, and later I wanted it to be set NOHUP so that it won't be killed when I exit the system. So I used disown, but later I found the manual says I should have used disown -h to set NOHUP. I want to check if my process is set NOHUP or not successfully. If not, what can I do to set it to be NOHUP?
UPDATE
I know two ways my be helpful:
1) Whenever a process is running over nohup It writes output on ~/nohup.out . So you can check this file by running command find -cmin 2. It shows you if nohup.out is changing each 2 seconds or not.
If it is changing you would understand that sth is running by nohup command, after that you can check it with lsof and continue your checking...
2) If you logout from specific user andgo to tty then do ps aux | grep <user> or ps aux | grep ? then you can understand that is running with nohup command... because there is no pts then it shows you ? instead...
useful command:
ps aux | grep <program> | awk -F" " '{print $7}'
Hope to be helpful

Resources