Recent

Author Topic: Low level OS API in Linux?  (Read 377 times)

Nimral

  • Full Member
  • ***
  • Posts: 107
Low level OS API in Linux?
« on: February 17, 2020, 01:13:28 pm »
Coming from Windows, I wonder what API I can use in Linux to get at low-level OS functions. Specifically I am after the following functionalities:

- shutdown the machine (shutdown -now equivalent)
- get the volume serial number of a drive (udevadm info --query=all --name=/dev/sda | grep ID_SERIAL equivalent)

currently I am using redirected shell commands, I am looking for a direct API or a management interface like WMI.

Thanx, Armin
Lazarus 1.8 on Windows 10/7, VMWare Workstation 12

Thaddy

  • Hero Member
  • *****
  • Posts: 9809
Re: Low level OS API in Linux?
« Reply #1 on: February 17, 2020, 04:34:16 pm »
 first unix shutdown:
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unix;
  3. begin
  4.   fpsystem('shutdown -P now');
  5. end.
I am more like donkey than shrek

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8108
Re: Low level OS API in Linux?
« Reply #2 on: February 17, 2020, 04:48:36 pm »
Linux is only a kernel, with say 400 syscalls, and some info and tricks with /proc.

For the rest there are some libraries, but not even close to the winapi with its ten thousands + calls.

Some higher level desktop libraries communicate via DBus, that can be something to look into too.

Nimral

  • Full Member
  • ***
  • Posts: 107
Re: Low level OS API in Linux?
« Reply #3 on: February 17, 2020, 07:17:40 pm »
first unix shutdown:
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unix;
  3. begin
  4.   fpsystem('shutdown -P now');
  5. end.

Thanks, Thaddy, that's what I have now. I was after a binary API like in Windows instead of shell program calls. I'll try to see where following marcov's lead will bring me.

Armin.
« Last Edit: February 17, 2020, 07:26:07 pm by Nimral »
Lazarus 1.8 on Windows 10/7, VMWare Workstation 12

MarkMLl

  • Hero Member
  • *****
  • Posts: 711
Re: Low level OS API in Linux?
« Reply #4 on: February 17, 2020, 07:42:23 pm »
I think that setting the system to runlevel 0 should do it, but I've not investigated in depth whether that's done by a single kernel call, by sending some sort of message to the init process, or womthing else entirely. However expect the physical act of powering off to be system-specific and very much dependant on having the right hardware support in the kernel, I think it's related to ACPI on PCs.

Be warned that I've screwed an SDCard by powering off a Raspberry Pi abruptly (possibly teleinit 0, I forget). And I mean screwed: beyond all salvage even using engineering commands issued by an Arduino.

Link below looks like a fairly useful summary.

https://superuser.com/questions/108704/how-to-shutdown-a-computer-instantly-1-to-5-secs-without-using-a-physical-swit/108705

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

winni

  • Hero Member
  • *****
  • Posts: 1158
Re: Low level OS API in Linux?
« Reply #5 on: February 17, 2020, 08:44:18 pm »
Hi!

The setting of the runlevels and the initialization of the related units is the job of the init process.

So shutdown -h now does the same as init 0

And don't be astonished about runlevel 6: this means reboot

Winni