Programmatically close the Browser from Linux Terminal in Chrome OS? - linux

I am trying to write a bash script that will automate some activity in the Browser on my Chromebook, and part of the workflow involves closing the Browser. I can't for the life of me figure out how to accomplish this.
pkill -9 [PID] doesn't work -- the Chrome Browser doesn't show up when listed, and it can't even be killed from task manager.
Any ideas?

The argument to pkill is not a PID.
"pkill chrome" would work.
$ /usr/bin/google-chrome-stable &
[1] 11653
$
$ ps
PID TTY TIME CMD
264 pts/1 00:00:00 bash
11879 pts/1 00:00:04 chrome
11883 pts/1 00:00:00 cat
11884 pts/1 00:00:00 cat
11894 pts/1 00:00:00 chrome
11895 pts/1 00:00:00 chrome
11897 pts/1 00:00:00 nacl_helper
11900 pts/1 00:00:00 chrome
11919 pts/1 00:00:01 chrome
11921 pts/1 00:00:00 chrome
11922 pts/1 00:00:00 chrome
11936 pts/1 00:00:00 chrome
11944 pts/1 00:00:00 chrome
11945 pts/1 00:00:01 chrome
12067 pts/1 00:00:00 chrome
12097 pts/1 00:00:00 ps
$
$ pkill chrome
$
[1]+ Done /usr/bin/google-chrome-stable
$ ps
PID TTY TIME CMD
264 pts/1 00:00:00 bash
12100 pts/1 00:00:00 ps
$

Related

Change process title/name in bash script

There is a field in process object in node.js: process.title
That field allows you to change process name displayed in top or ps command on linux.
Is there some way to do this for and in bash script also?
Changing the command line reference from running processes is possible on *NIX with /proc filesystem :
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 bash
719 tty4 00:00:00 ps
$ echo "toto" > /proc/106/comm
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 toto
719 tty4 00:00:00 ps
$
And yes, it's not the prettiest way to do so.

Different PID for the same process

I am just trying to understand more about the PID column when running the ps command.
If I have two terminal windows open, in the first one I run the following command
firefox &
Then run the ps command in BOTH and get the following output from the first window
PID TTY TIME CMD
16814 pts/1 00:00:00 bash
16822 pts/1 00:00:04 MainThread
16881 pts/1 00:00:02 Privileged Cont
16938 pts/1 00:00:00 WebExtensions
17026 pts/1 00:00:00 Web Content
17081 pts/1 00:00:00 ps
And the following in the second
PID TTY TIME CMD
16794 pts/0 00:00:00 bash
17082 pts/0 00:00:00 ps
In both outputs we see the shell process. Why do they not have the same PID, even if it has the same process name.

Run Webserver in the background

In order to have my site running on a webserver i have to manualy login into it with these commands:
ssh IP
add password
cd chn
source bin/activate
cd chn
python3 manage.py runserver IP:80
And that is it! How i can do all this process to run in the background?
PS. The server is running on Linux/Ubuntu14.0 i think. If i put & at the end of each line, i will see them in my terminal, but i am afraid that it will stop all, when i close my mac/termina etc.
root#localhost:~# ps aux | grep 1373
root 30873 0.0 0.0 11724 680 pts/1 S+ 14:35 0:00 grep --color=auto 1373
root#localhost:~# ps aux | grep 30827
root 30875 0.0 0.0 11724 676 pts/1 S+ 14:36 0:00 grep --color=auto 30827
root#localhost:~# ps aux | grep 30835
root 30835 0.2 3.0 100644 31024 pts/0 S 14:33 0:00 python3 manage.py runserver IP:80
root 30877 0.0 0.0 11724 676 pts/1 S+ 14:36 0:00 grep --color=auto 30835
Thank you!
it worked with this command Nohup python3 manage.py runserver 5.83.45.64:80 &

How does 'kill -STOP and kill -CONT' work?

I'm facing an issue.
We have a clean script using to clean old files, and sometimes we need stop it for and will start it again later. Like the below processes. We use kill -STOP $pid and kill -CONT $pid in check.sh to control the clean.sh, $pid is all the pids of clean.sh (at there, they are 23939, 25804):
root 4321 0.0 0.0 74876 1184 ? Ss 2015 0:25 crond
root 23547 0.0 0.0 102084 1604 ? S 2015 0:00 \_ crond
root 23571 0.0 0.0 8728 972 ? Ss 2015 0:00 \_ /bin/bash -c bash /home/test/sbin/check.sh >>/home/test/log/check.log 2>&1
root 23577 0.0 0.0 8732 1092 ? S 2015 0:00 \_ bash /home/test/sbin/check.sh
root 23939 0.0 0.0 8860 1192 ? S 2015 0:45 \_ bash /home/test/bin/clean.sh 30
root 25804 0.0 0.0 8860 620 ? S 2015 0:00 \_ bash /home/test/bin/clean.sh 30
root 25805 0.0 0.0 14432 284 ? T 2015 0:00 \_ ls -d ./455bb4cba6142427156d2b959b8b0986/120x60/ ./455bb4cba6142427156d2b959b8b0986/80x
root 25808 0.0 0.0 3816 432 ? S 2015 0:00 \_ wc -l
Once the check.sh stopped clean.sh, hours later, check.sh started clean.sh, but there is a strange thing, after a stop and continue, there is a child process 'ls -d ....', it's still stopping.
Could you tell me if it's caused by wrong use of the signal? And how can I modify it?
ok, same like my description is not clear, my bad English...
Not sure what's the reason, but there is a way to sovle it:
kill -CONT $pid
pkill -CONT -P $pid
This will continue the child process.

How to see a terminal output from a previously closed terminal

I connect to a remote server using SSH
I was compiling using cmake and then make, it's not common to have a progress percentage in compilation process, but this time it has. I was watching the compilation process until my internet connection failed, so puTTY closed the session and I had to connect again to my server. I though that all the progress was lost, but i first make sure by watching the processes list by ps aux command, and I noticed that the processes related to the compilation are still running:
1160 tty1 Ss+ 0:00 /sbin/mingetty tty1
2265 ? Ss 0:00 sshd: root#pts/1
2269 pts/1 Ss 0:00 -bash
2353 pts/1 S+ 0:00 make
2356 pts/1 S+ 0:00 make -f CMakeFiles/Makefile2 all
2952 ? S 0:00 pickup -l -t fifo -u
3085 ? Ss 0:00 sshd: root#pts/0
3089 pts/0 Ss 0:00 -bash
3500 pts/1 S+ 0:01 make -f src/compiler/CMakeFiles/hphp_analysis.dir/bui
3509 pts/1 S+ 0:00 /bin/sh -c cd /root/hiphop/hiphop-php/src/compiler &&
3510 pts/1 S+ 0:00 /usr/bin/g++44 -DNO_JEMALLOC=1 -DNO_TCMALLOC=1 -D_GNU
3511 pts/1 R+ 0:03 /usr/libexec/gcc/x86_64-redhat-linux6E/4.4.4/cc1plus
3512 pts/0 R+ 0:00 ps ax
I would like to know if is possible to watch the current progress of the compilation by watching the previously closed terminal output. Something similar like 'cat /dev/vcsa1' or something
As per the comment above, you should have used screen.
As it is, you could try to peek at the file descriptors used by sshd and the shell that you started, but I don't think this will get you very far.

Resources