How to detect system power events such as suspend, hibernate, etc - linux

I want to make a Linux application that send a message to a remote host when a local system (where the application runs) is going to suspend, hibernate or shutdown. I googled how to do this and found acpi_listen but it doesn't work.
Here is the result of ps aux | grep acpi on the system I tested (Ubuntu 10.04 LTS):
root 35 0.0 0.0 0 0 ? S Dec03 0:00 [kacpid]
root 36 0.0 0.0 0 0 ? S Dec03 0:00 [kacpi_notify]
root 37 0.0 0.0 0 0 ? S Dec03 0:00 [kacpi_hotplug]
root 934 0.0 0.0 2048 872 ? Ss Dec03 0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
Communicating with acpid directly via a UNIX domain socket wouldn't work since that's the way acpi_listen works, although I didn't try it. Is there any other way?

Listen for them over D-Bus.

Related

Does linux process VSZ equal 0 mean kernel space application?

I notice some process always have VSZ as 0
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 19356 1400 ? Ss Jun13 0:00 /sbin/init
root 2 0.0 0.0 0 0 ? S Jun13 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Jun13 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S Jun13 0:01 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Jun13 0:00 [stopper/0]
root 6 0.0 0.0 0 0 ? S Jun13 0:03 [watchdog/0]
root 7 0.0 0.0 0 0 ? S Jun13 0:00 [migration/1]
how to understand why they have 0 VSZ?
VSZ is the Virtual Memory Size. It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.
So, the top command screenshot you shared showing VSZ values equaling 0, means that those processes are not using VSZ.
NOTE: They are kernel threads and memory statistics are irrelevant for them as they use kernel memory. Just to visualize kernel processes, press c when top command is running and it will show you all [bracketed] entries in last column named COMMAND.
You can get more details on VSZ and learn about its counterpart RSS (Resident Set Size) from here.

nginx is installed but site does not load

I installed LEMP with this tutorial I have done all it says but when I enter my server ip address in my browser it takes some time to load the page and it seems like my browser is doing some processes to load the page but at last the page is blank.
I'v checked all the installation again and they were all installed.
I'v installed apache at the past and I know for apache server if you enter server ip address it shows " apache is functioning " but It's my first time installing nginx ; I want to install DirectAdmin and I don't know nginx is installed or not.
If anyone is familiar with nginx and can help me, I'll be apreciate that.
Update: When I use service nginx status it shows nginx is running.
Update: Flowing are the results of my checkings:
Results of netstat -tulpn | grep :80 :
tcp 0 0 0.0.0.0:80 0.0.0.0:* LIST EN 10302/nginx
Results of ps aux | grep nginx :
nginx 8556 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8557 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8558 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8559 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8560 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
root 10302 0.0 0.0 96032 1980 ? Ss 09:11 0:00 nginx: master p rocess /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 10304 0.0 0.0 96436 2692 ? S 09:11 0:00 nginx: worker p rocess
nginx 10305 0.0 0.0 96436 2692 ? S 09:11 0:00 nginx: worker p rocess
nginx 10306 0.0 0.0 96436 2660 ? S 09:11 0:00 nginx: worker p rocess
nginx 10307 0.0 0.0 96436 2672 ? S 09:11 0:00 nginx: worker p rocess
root 12564 0.0 0.0 103312 856 pts/0 S+ 09:59 0:00 grep nginx
FIIIIINNNNNNAAAAAALLLLLLLY I Found the problem!
The problem was with my firewall.
If anyone else has the same problem it may be the firewall settings problem like mine So Do the flowing to fix this:
vim /etc/sysconfig/iptables
in the opened file find this line :
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
Check that --dport 80 is set to the port that you entered in /etc/nginx/conf.d/default.conf if its something else like --dport 22 change it to your default port.
Update:
After you changed the port you should run this code:
service iptables restart
And this is the page shows nginx is running :

in linux - show a list of all processes and note if they are running or suspended

I'm new to linux.
How can I show a list of all processes that says about each process if it's running or suspended?
I've tried
ps -ef|grep myusername
but it doesn't say if the processes are running or not.
also tried
ps ux
same thing, it doesn't say if the processes are running or not.
I'm looking for something like this list:
I get this list when I move a process to background, I don't know how to see it otherwise...
You can use "ps" to list processes, This (ps aux) will list all the processes. Given an example output of it below.
ps aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 189160 9376 ? Ss 15:51 0:04 /usr/lib/systemd/systemd --switched-root --system --deserialize 20
root 2 0.0 0.0 0 0 ? S 15:51 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 15:51 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 15:51 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 15:51 0:06 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 15:51 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 15:51 0:04 [rcuos/0]
By checking the STAT of the process ( UNDER "STAT" ) you can identify the process states, Below are some possible states codes.
R running or runnable (on run queue)
D uninterruptible sleep (usually IO)
S interruptible sleep (waiting for an event to complete)
Z defunct/zombie, terminated but not reaped by its parent
T stopped, either by a job control signal or because it is being
traced
You can type "man ps" to get more info.
You can use htop to see the list of processes and there is a column for process state
What does a C process status mean in htop?
http://www.howtogeek.com/howto/ubuntu/using-htop-to-monitor-system-processes-on-linux/
ps -p PID -o comm=
Enter the code above where PID is PID of the process.
Following command will be more helpful to you.
Use the command : sudo lsof -i -n -P
This command lists the Application Name, PID, User, IP version, Device ID and the Node with Port Name. It shows both TCP and UDP.
Variations :
To format it in a nice, readable way; use :
sudo lsof -i -n -P | more
To view view only TCP connections :
sudo lsof -i -n -P | grep TCP | more
To view view only UDP connections :
sudo lsof -i -n -P | grep UDP | more

apache2 multiple instances under www-data

I am running apache2 on my RaspberryPi, mainly to interface with an mpd php client for streaming audio. After a month or so, I see the following:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1496 www-data 20 0 55900 17m 2112 S 0.0 9.3 0:30.32 apache2
7198 www-data 20 0 54868 15m 2188 S 0.0 8.4 0:10.57 apache2
7182 www-data 20 0 54868 15m 2168 S 0.0 8.3 0:11.67 apache2
1497 www-data 20 0 53844 15m 2132 S 0.0 8.2 0:07.58 apache2
2609 mysql 20 0 314m 15m 280 S 0.7 8.1 71:58.52 mysqld
7185 www-data 20 0 54868 14m 2180 S 0.0 8.1 0:08.71 apache2
7183 www-data 20 0 54868 14m 2120 S 0.0 8.1 0:14.36 apache2
1499 www-data 20 0 53844 14m 2144 S 0.0 8.0 0:07.73 apache2
1932 mpd 20 0 81204 8152 584 S 0.0 4.3 145:46.25 mpd
7211 www-data 20 0 45652 8004 2204 S 0.0 4.2 0:01.65 apache2
3318 www-data 20 0 45652 7944 2140 S 0.0 4.2 0:03.43 apache2
7210 www-data 20 0 45652 7784 2176 S 0.0 4.1 0:01.28 apache2
1965 root 20 0 44532 5268 216 S 0.0 2.8 1:53.06 apache2
7168 www-data 20 0 45652 7956 2140 S 0.0 4.2 0:02.42 apache2
Along with mpd and mysql, and the root apache2 process, 11 apache2 process running as www-data. On reboot, I see 5 apache2 processes under www-data.
Why are more processes spawnded, and not closed down? I continue to see this grow until there are 20+ processes, which slows down the something this small with limited resources.
Why are new processes spawned, then persist? Can I control this in conf.d (I have tried, but the feedback process takes a few days or week, so it's hard to tell).
Apache - when running in pre-fork mode - spawns a pool of worker processes in order to keep the response time low. Every worker will be responsible for a certain request. So, if there are 11 workers running, apache could serve 11 requests in "parallel" without spawning a new process (what would take a significant amount of time)
Apache spawns that workers / and keeps them alive intelligently, but you can set the maximum and minimum amount of workers in the apache2.conf

Memory usage with high precision

How can I get high precision memory usage per proccess with "ps aux"?
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 3672 1984 ? Ss Dec11 0:07 /sbin/init
root 2 0.0 0.0 0 0 ? S Dec11 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Dec11 0:23 [ksoftirqd/0]
root 6 0.0 0.0 0 0 ? S Dec11 0:00 [migration/0]
...
I need more than 1 digit after point.
Maybe I can format column with %MEM?
Look into the proc filesystem /proc/[pid]/status, /proc/[pid]/statm, /proc/[pid]/smaps.
To get fully detailed memory map /proc/[pid]/maps
Read the proc(5) manual page for all the details.
the ps command have that. you can type man ps for detail.
when the termianl show info after you typed it, you can type /memory , then heighlight contain 'memory''s string. you can type n show next palace with memory.

Resources