Adventures in the land of Linux signalling

If you have a process that is consuming too much CPU or I/O you can pause it by sending it a STOP signal, If it has been called by a shell that you have access too you can simply press CTRL^Z, the job will be paused and put in the back ground. execute fg to start the job

But if the process is not a shell command or is owned by another shell you can still pause the job by sending it a SIGSTOP signal using the kill command

kill -19 <pid>

kill -s SIGSTOP <pid>

This will put the process into the background.

To un-pause the process send it a SIGCONT (continue) signal

kill -18 <pid>

kill -s SIGCONT <pid>

If a process forks a child but does not call wait() if the child dies first the process will still stick around in the process table until someone picks up the exit code, if no one picks up the exit code init will do it

seamus@ubuntu144:~$ ps -U seamus -v
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
2772 pts/23   S      0:00      0   955 26460  4380  0.0 -su
3177 pts/11   S      0:00      0   955 26464  4400  0.0 -su
3219 pts/11   S+     0:08      0     2 43253   356  0.0 ./fork.exe
3220 pts/11   S+     0:00      0     2 82317   104  0.0 ./fcrk.exe
3221 pts/23   R+     0:00      0    84 22555  1076  0.0 ps -U seamus -v

seamus@ubuntu144:~$ kill 3220

seamus@ubuntu144:~$ ps -U seamus -v
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
2772 pts/23   S      0:00      0   955 26460  4380  0.0 -su
3177 pts/11   S      0:00      0   955 26464  4400  0.0 -su
3219 pts/11   S+     0:08      0     2 43253   356  0.0 ./fork.exe
3220 pts/11   Z+     0:00      0     0     0     0  0.0 [fork.exe] <defunct>
3222 pts/23   R+     0:00      0    84 22555  1072  0.0 ps -U seamus -v

If I add a wait call after the fork.. #include

printf("child exited with status of = %d\n",wait(&exitstatus));

And send the child a kill signal then all it good, no zombie and the parent receives the signal

seamus@ubuntu144:~$ ps -U seamus -v
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
2772 pts/23   S      0:00      0   955 26460  4380  0.0 -su
3177 pts/11   S      0:00      0   955 26548  4620  0.0 -su
3334 pts/11   S+     0:08      0     2 43253   352  0.0 ./fork.exe
3340 pts/11   S+     0:00      0     2 43253   100  0.0 ./fork.exe
3343 pts/23   R+     0:00      0    84 22555  1076  0.0 ps -U seamus -v

seamus@ubuntu144:~$ kill 3340

seamus@ubuntu144:~$ ps -U seamus -v
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
2772 pts/23   S      0:00      0   955 26460  4380  0.0 -su
3177 pts/11   S      0:00      0   955 26548  4620  0.0 -su
3334 pts/11   S+     0:08      0     2 43253   352  0.0 ./fork.exe
3344 pts/23   R+     0:00      0    84 22555  1072  0.0 ps -U seamus -v

seamus@ubuntu144:~$ ./fork.exe 
I am the parent process 
I am the parent of the child proccess ID 3340
child exited with status of = 3340

DD and signals

Sending signals to the DD command to force it to display a progress update.

while killall -USR1 dd; do sleep 1; done


guess@desktop:~$ dd if=/dev/urandom of=file bs=512 
253427+0 records in
253426+0 records out
129754112 bytes (130 MB) copied, 11.1867 s, 11.6 MB/s
276324+0 records in
276323+0 records out
141477376 bytes (141 MB) copied, 12.1911 s, 11.6 MB/s
299038+0 records in
299037+0 records out
153106944 bytes (153 MB) copied, 13.1956 s, 11.6 MB/s
321950+0 records in
321949+0 records out
164837888 bytes (165 MB) copied, 14.2001 s, 11.6 MB/s