18 Eylül 2022 Pazar

init.d Nedir

init.d vs systemd
Hangisini kullandığımızı anlamanın en kolay yolu şöyle. Eğer gerçekten systemd kullanılıyorsa ayrıca systemctl komutu da olmalı. WSL Linux'ta systemd kullanılıyor gibi görünse de aslında kullanmıyor
$ file /sbin/init
/sbin/init: symbolic link to /lib/systemd/systemd
Örnek 
/etc/init.d altında bir dosya yaratırız. Şöyle yaparız
cd /etc/init.d
touch mysqld_multi
chmod +x /etc/init.d/mysqld_multi
Bu dosyaya çalışmasını istediğimiz komutları yazarız. Daha sonra servisi bilgisayar açılırken çalışır hale getiririz. Şöyle yaparız
# Add mysqld_multi service to the default runlevels with the following command:

update-rc.d mysqld_multi defaults


14 Eylül 2022 Çarşamba

pidstat komutu

Giriş
Açıklaması şöyle
A common (and pretty good) answer is to use top. But there is one issue with top it’s difficult to copy the output to a scratch pad where you keep details about your debugging or if you’d want to send the output to someone else.

To get an output which is easy to read and copy friendly, run pidstat | head -n 20 or e.g. pidstat -u 5 60 to get updates every 5 seconds for the next 6 seconds.
Örnek
Şöyle yaparız
$ pidstat | head -n 20
Linux 5.13.0-40-generic (tsunami)       05/03/2022      _x86_64_        
(8 CPU)
UID       PID    %usr %system  %wait    %CPU   CPU  Command
  0         1    0.00    0.01   0.00    0.01     7  systemd
  0         2    0.00    0.00   0.00    0.00     1  kthreadd
  0        12    0.00    0.00   0.00    0.00     0  ksoftirqd/0
  0        13    0.00    0.06   0.02    0.06     7  rcu_sched
  0        14    0.00    0.00   0.00    0.00     0  migration/0
  0        19    0.00    0.00   0.00    0.00     1  migration/1
  0        20    0.00    0.00   0.00    0.00     1  ksoftirqd/1
Açıklaması şöyle
%usr to find high user space time allocation. This would indicate an application in need of scaling for example.

%system to find high system / kernel space time allocation. Remember that this could be due to driver issues or other similar kernel level problems.

%wait would yet again indicate I/O latencies.





mpstat komutu

-P seçeneği
Açıklaması şöyle
mpstat -P ALL 1 will give you statistics similar to vmstat but with a per CPU breakdown.
Örnek
Şöyle yaparız
$ mpstat -P ALL 1 15:11:50
Linux 5.13.0-40-generic (tsunami)       05/03/2022      _x86_64_        (8 CPU)
CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %idle
all    6.67    0.00    2.52    0.00    0.00    0.13    0.00  90.69
  0    4.00    0.00    2.00    0.00    0.00    0.00    0.00  94.00
  1   10.10    0.00    4.04    0.00    0.00    0.00    0.00  85.86
  2    8.08    0.00    1.01    0.00    0.00    0.00    0.00  90.91
  3    4.04    0.00    1.01    0.00    0.00    0.00    0.00  94.95
  4    4.04    0.00    3.03    0.00    0.00    1.01    0.00  91.92
  5   10.00    0.00    1.00    0.00    0.00    0.00    0.00  89.00
  6    7.07    0.00    3.03    0.00    0.00    0.00    0.00  89.90
  7    6.00    0.00    5.00    0.00    0.00    0.00    0.00  89.00



uptime komutu

Örnek
Şöyle yaparız
$ uptime 11:19:45 up 1:43, 37 users, load average: 2.44, 2.35, 2.40
Açıklaması şöyle
The last three numbers indicate the load average for the last 1, 5, & 15 minutes.

9 Eylül 2022 Cuma

/dev/stdin Dosyası

Giriş
Açıklaması şöyle. Yani Linux'ta bu dosyadan okumak aslında stin'in tüketmez.
The /dev/stdin, /dev/stdout, /dev/stderr and /dev/fd/x are special files that were added to various Unices in the 80s so the file descriptors of a process could be referred to by name.

On those Unices, opening /dev/stdin (a character device file) got you a file descriptor that was a duplicate of stdin (fd 0), so the equivalent of doing dup(0)³.

When Linux added a similar feature in the '90s, the implementation was significantly different and incompatible.

On Linux, those /dev/std..., /dev/fd/x files are not special character device files but symbolic links to /proc/self/fd/x, and those in turn are magic symlinks to the file that is opened on fd x.

So, opening /dev/stdin there is not the same as dup(0); it's opening the original file anew assuming you have permissions to do so, and from the start (not at the offset stdin is currently pointing within the file) and in the requested mode. That also means that if you're reading/writing/seeking from the fd you get which is independent from fd 0, you're not updating stdin's offset within the file.

Cygwin copied the Linux way when it added a similar feature in the 2000s. Most if not all other Unices behave the original way (when they support those /dev/fd/x at all).


6 Eylül 2022 Salı

FreeBSD Nedir

Giriş
Açıklaması şöyle
FreeBSD underpins macOS. This is not Linux, but it is Unix, so they have a reasonable degree of similarity, especially in terms of commands, shell, etc. However, there is a fair degree of divergence under the covers: macOS does not offer the same fine-grain control. This can negatively impact you if you intend to do low-latency development. For example, you want to control which cores your threads are pinned to.