system-calls

Golang catch signals

╄→尐↘猪︶ㄣ 提交于 2019-12-20 09:36:18
问题 I want to implement a "process wrapper" in Go. Basically what it will do, is launch a process (lets say a node server) and monitor it (catch signals like SIGKILL, SIGTERM ...) I think the way to do is to launch the node server in a go routine using syscall.Exec : func launchCmd(path string, args []string) { err := syscall.Exec(path, args, os.Environ()) if err != nil { panic(err) } } Then I'd like to catch every possible signals generated by the command executed by syscall . I'm pretty new to

assembly system call non-effective

倖福魔咒の 提交于 2019-12-20 07:47:09
问题 I want to print AAAA with the following: BITS 32; ;write; push 0x41414141; pop ecx ; mov eax, 4 ; write is syscall 4 for Ubuntu 32-bit mov ebx, 1 ; stdout mov edx, 4 ; int 0x80 ; ;exit; mov eax, 1 ; mov ebx, 0 ; int 0x80 ; Yet, once assembled and linked this code only exits, no errors, what is wrong ? 回答1: A quick fix of your code: push 0x41414141 ; put 'AAAA' into stack memory mov ecx,esp ; pointer to the 'AAAA' mov eax, 4 ; write is syscall 4 for 32-bit Linux mov ebx, 1 ; stdout mov edx, 4

pass parameter using system command

馋奶兔 提交于 2019-12-20 05:36:14
问题 I have an executable program that runs in several pc's in a network. At first it gets the host name (pc-001.. pc-013 etc). Then i need to mount a network drive (server1) on even pc's and (server2) on odds one based on its host name. My problem is that i use system call to run dos command 'net use' for example system ("net use x: \\\\server1\\shares /user:username pass"); How can i pass a variable to username? username is the host name which i know its value and pass is the same for all

Why doesn't this attempt at using sys_write do anything?

喜你入骨 提交于 2019-12-20 04:38:39
问题 Here it is: .SECTION .data msg: .string "AAAA" .SECTION .text .globl _start _start: mov $1, %rax mov $1, %rdi mov msg, %rsi mov $4, %rdx syscall Not only does this code not segfault, it also outputs nothing. According to what I've read, a program should call sys_exit, or it would segfault, but this does not happen. 回答1: mov msg, %rsi This instruction will interpret the data at "msg" as 64-bit value and load that value into the register rsi . The instruction does NOT load the address of "msg"

How do non c languages interact with operating system?

微笑、不失礼 提交于 2019-12-20 03:19:17
问题 On linux (for example), we can directly make system calls using the api provided by OS (open/close/read/write) or we can use functions provided by libc (fopen etc) in C. How is it achieved in other languages? 回答1: Your initial premises are wrong: on Linux, when you call, say, open(2) in your C code, you're not making the syscall but rather calling the function provided by glibc (or whatever implementation of the C standard library your program happens to be using—there are others, such as

Multiple kernel modules intercepting same system call and crash during unload

北慕城南 提交于 2019-12-20 02:58:27
问题 I'm working on system call interception (for open() system call) and I got one problem: I have two kernel modules ( mod1 and mod2 ) and both of them are trying to intercept open() syscall. I've loaded mod1 first and then mod2 . The mod1 intercepted open() by: original_open1 = sys_call_table[__NR_open]; sys_call_table[__NR_open] = mod1_open; Here original_open1 would be sys_open . After this, mod2 intercepted open() by: original_open2 = sys_call_table[__NR_open]; sys_call_table[__NR_open] =

C / C++ / C#: Howto do “mount -a”

巧了我就是萌 提交于 2019-12-20 02:13:29
问题 Question: In C/C++/C#. (I need it for C#, but C and C++ is also fine). How can I do a mount -a on Linux. I mean programmatically, without starting a process like system("mount -a"); Edit: Note the "-a". My question is not actually about how to mount A mountpoint. It's about how to mount ALL mountpoints in /etc/fstab. That means parsing the file, extracting the mountpoints, check if already mounted, and only if not already mounted, mount... 回答1: getmntent can help you read /etc/fstab (and then

C / C++ / C#: Howto do “mount -a”

扶醉桌前 提交于 2019-12-20 02:13:19
问题 Question: In C/C++/C#. (I need it for C#, but C and C++ is also fine). How can I do a mount -a on Linux. I mean programmatically, without starting a process like system("mount -a"); Edit: Note the "-a". My question is not actually about how to mount A mountpoint. It's about how to mount ALL mountpoints in /etc/fstab. That means parsing the file, extracting the mountpoints, check if already mounted, and only if not already mounted, mount... 回答1: getmntent can help you read /etc/fstab (and then

How do I wait for a keystroke interrupt with a syscall on Linux?

橙三吉。 提交于 2019-12-20 01:38:40
问题 I want to receive an interrupt when the user presses a special keystroke like F1-12 in my program, which is written in nasm. I simply need to wait for a function keystroke at the start of my main function. I know that this is possible with the BIOS's int 16h , which returns a scancode. How can I do this under Linux? 回答1: The necessary code for this is rather complicated; I eventually figured out how to check for F1 in C with raw ioctl, read, and write. The translation to nasm should be

return value in vfork() system call

核能气质少年 提交于 2019-12-19 18:16:14
问题 Considering the below code : int main() { int pid; pid=vfork(); if(pid==0) printf("child\n"); else printf("parent\n"); return 0; } In case of vfork() the adress space used by parent process and child process is same, so single copy of variable pid should be there. Now i cant understand how this pid variable can have two values returned by vfork() i.e. zero for child and non zero for parent ? In case of fork() the adress space also gets copied and there are two copy of pid variable in each