system-calls

Seeing all the system calls that were made by a Java program

折月煮酒 提交于 2019-12-19 17:56:28
问题 How can I see which system calls my Java program is making? Is there a tool that will do this on Linux? 回答1: Use strace: strace java your_program 回答2: Use strace. But there is is trick for my case. Option -f is needed. For example, the following code: public class Foo { public static void main (String [] args) { System.out.println("XXX"); } } After running javac Foo.java to compile it, strace java Foo 2>&1 | grep write print nothing. But strace -f java Foo 2>&1 | grep write prints: [pid 11655

If close(2) fails with EIO, will the file descriptor still be deleted?

时光毁灭记忆、已成空白 提交于 2019-12-19 05:06:54
问题 If a close(2) system call fails with EIO, will the file descriptor still be deleted? If yes, is it not possible to handle a spurious IO error by retrying later? If no, how should one prevent a file descriptor leak? 回答1: That's a tricky question. However, the POSIX standard does cover it in the description of close(): If close() is interrupted by a signal that is to be caught, it shall return -1 with errno set to [EINTR] and the state of fildes is unspecified. If an I/O error occurred while

Get file size with stat syscall

…衆ロ難τιáo~ 提交于 2019-12-18 18:07:22
问题 I'm trying to get file size wit stat syscall with assembly (nasm): section .data encodeFile db "/home/user/file" section .bss stat resb 64 struc STAT .st_dev: resd 1 .st_ino: resd 1 .st_mode: resw 1 .st_nlink: resw 1 .st_uid: resw 1 .st_gid: resw 1 .st_rdev: resd 1 .st_size: resd 1 .st_atime: resd 1 .st_mtime: resd 1 .st_ctime: resd 1 .st_blksize: resd 1 .st_blocks: resd 1 endstruc _start: mov rax, 4 mov rdi, encodeFile mov rsi, stat syscall mov eax, dword [stat + STAT.st_size] There is 0 in

Linux write sys call using string on stack [duplicate]

邮差的信 提交于 2019-12-18 17:13:12
问题 This question already has an answer here : What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? (1 answer) Closed 2 years ago . I have just started to teach myself x86 assembly on linux from these video tutorials. Early on it teaches you how to use the write sys-call to print a string that is stored in the data section. Is it possible to use the write syscall to print a string that is stored on the stack. Here is the code I wrote to try and do this which doesn't seem to work.

Catching / blocking SIGINT during system call

天涯浪子 提交于 2019-12-18 16:49:25
问题 I've written a web crawler that I'd like to be able to stop via the keyboard. I don't want the program to die when I interrupt it; it needs to flush its data to disk first. I also don't want to catch KeyboardInterruptedException , because the persistent data could be in an inconsistent state. My current solution is to define a signal handler that catches SIGINT and sets a flag; each iteration of the main loop checks this flag before processing the next url. However, I've found that if the

Mechanism of clipboard of xwindow

做~自己de王妃 提交于 2019-12-18 06:53:54
问题 Can anybody explain the mechanism of clipboard of xwindow to me? For example, if I make a operation of open a file from gedit and copy the content of this file using ctrl+c. And then I open vim and use ctrl+v to paste the content into the new opened file. I know that it will use the buffer of xwindow to store the content. But I am curious how it works in the system level. More specifically, how the underlying linux kernel needs to do to handle this copy-paste operation? Is there any system

Mechanism of clipboard of xwindow

寵の児 提交于 2019-12-18 06:52:54
问题 Can anybody explain the mechanism of clipboard of xwindow to me? For example, if I make a operation of open a file from gedit and copy the content of this file using ctrl+c. And then I open vim and use ctrl+v to paste the content into the new opened file. I know that it will use the buffer of xwindow to store the content. But I am curious how it works in the system level. More specifically, how the underlying linux kernel needs to do to handle this copy-paste operation? Is there any system

In Linux, on entry of a sys call, what is the value in %eax? (not orig_eax)

断了今生、忘了曾经 提交于 2019-12-18 05:03:40
问题 When a syscall returns, I get the syscall return value in %eax, however on entry I am getting -38, which is 0xFFFFFFDA in hex. This is for both write/read. What is this number? Can it be used to safely differentiate an entry from an exit? 回答1: The -38 in eax on syscall entry is apparently ENOSYS (Function not implemented), and is put there by syscall_trace_entry in arch/x86/kernel/entry_32.S. I suppose it's safe to assume that it will always be there on syscall entry, however it can also be

How to check the value of errno?

三世轮回 提交于 2019-12-18 03:40:45
问题 I am using a system call and in case it fails, I need to do different things for different errnos. I need to write code that looks something like this: int res; res = systemCall(); if (res == -1) { if (errno == ENOMSG) { doSomething(); } else { doSomethingElse(); } } perror doesn't help, because it only prints the value. As for strerro - if it is what I need, I am not suer how to use it, because here it says that the actual string is not the same as the error. Quote from the man page: "(For

Capturing syscall stdout without writing to file in C/C++

做~自己de王妃 提交于 2019-12-17 21:16:23
问题 I want to read the std output of a system call into a C/C++ string. Can I do this without using a temp file? Perl //without file io $output = `echo hello`; C++ //with file io system ("echo hello > tmp"); std::fstream file ("tmp"); std::string s; file >> s; 回答1: Using C's popen (probably the simplest solution, even if it doesn't use C++'s iostream ): FILE *p = popen("echo hello", "r"); std::string s; for (size_t count; (count = fread(buf, 1, sizeof(buf), p));) s += string(buf, buf + count);