system-calls

system call to populate struct values

泄露秘密 提交于 2020-01-17 14:59:52
问题 I'm trying to populate struct values using system calls. My initial effort follows. However i get junk values from the print statement. int fd; int nbytes; struct message { char *from; char *to; int size; }; struct message m1={"me","you",10}; struct message m2; fd=creat("structfile",0644); nbytes=write(fd,&m1,sizeof(m1)); read(fd,&m2,nbytes); printf("%s %s %d",m2.from,m2.to,m2.size); Is there another way to do this? (I'm thinking of the way that structures like hostent and dirent are filled

Mips Output syscall

 ̄綄美尐妖づ 提交于 2020-01-17 11:14:04
问题 li $s5, 2 add $a0, $s5, $0 li $v0, 4 syscall Why system out is (null) in spim ? 回答1: Looks like you are trying to print an int, but the system call code you are providing stands for "print string". As you have no label called 2 (hence no string starting at address of label 2 ), the console prints out (null) . Try this li $a0, 2 #integer to be printed li $v0, 1 #system call code 1: print_int syscall Now it should print 2 Check out this table for syscall op codes. 来源: https://stackoverflow.com

How do I get the output of a Linux System Call in C/C++?

你。 提交于 2020-01-16 04:54:11
问题 I've added a simple helloworld system call to my Linux Kernel. sys_helloworld #include <linux/kernel.h> asmlinkage long sys_helloworld(void) { printk("Hello world\n"); return 0; } It just print out Hello world to the kernel log. I called sys_helloworld system call like so : #include <stdio.h> #include <linux/kernel.h> #include <sys/syscall.h> #include <unistd.h> int main() { long int a = syscall(314); // 314 is the line number of sys_helloworld in syscall table printf("System call sys

Filter out broken pipe errors from template execution

混江龙づ霸主 提交于 2020-01-13 19:28:15
问题 This is similar to Filter out broken pipe errors , but with complications - when a user presses the "stop" button on their browser while a template is executing (html/template.Execute or text/template.Execute), a broken pipe error occurs. However, I believe that the error returned by the text/template package is simply of type *errors.errorString as the broken pipe message appears to be wrapped in some other informational text and so no type assertion can be made to net.OpErr for comparison

How synchronized keyword in java have been implemented?

Deadly 提交于 2020-01-13 10:56:13
问题 I'm reading operating system and I came across several problems for inter-process communication. These can be solved by using monitor concepts which java provide via synchronized keyword. I wish to know how synchronized keyword have been implemented? I tried to look at the source but I couldn't able to find it. Are synchronized are using system calls like down up ( which semaphore uses basically) to monitor the locks? Does JVM help in this process? I'm a novice in Java, I wish to know how

Socket reading and timestamps

放肆的年华 提交于 2020-01-13 10:46:29
问题 When reading from a (non-stream) socket in Linux, I can get the (hardware-generated) timestamp of the last received message via a ioctl(sock, SIOCGSTAMP, &tv) . However, this poses two problems: It is another syscall (I'm receiving about 24000 messages per second, so each syscall is notifiable) If using this approach, I can only read() one message at a time, followed by the ioctl() to get the timestamp. (If I'm reading more than one message in a read() -call, the following ioctl only yields

Using `read` system call on a directory

旧巷老猫 提交于 2020-01-11 09:52:32
问题 I was looking at an example in K&R 2 (8.6 Example - Listing Directories). It is a stripped down version of Linux command ls or Windows' dir . The example shows an implementation of functions like opendir , readdir . I've tried and typed the code word-by-word but it still doesn't work. All it does is that it prints the a dot (for the current directory) and exits. One interesting thing I found in the code (in the implementation of readdir ) was that it was calling the system calls like open and

significance of (void*) -1 [duplicate]

可紊 提交于 2020-01-11 05:33:08
问题 This question already has answers here : Is ((void *) -1) a valid address? (3 answers) Closed 3 years ago . I was looking at the documentation of sbrk system call and found this: On success, sbrk() returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error, (void *) -1 is returned, and errno is set to ENOMEM . Now, What's the significance of (void *) -1 ? What is the exact memory address it points to? (if

So malloc doesn't invoke any syscall?

爱⌒轻易说出口 提交于 2020-01-11 05:13:06
问题 Related code: write(-1, "test", sizeof("test")); void * p = malloc(1024); void * p2 = malloc(510); write(-1, "hi", sizeof("hi")); Related strace output: write(4294967295, "test\0", 5) = -1 EBADF (Bad file descriptor) brk(0) = 0x601000 brk(0x622000) = 0x622000 write(4294967295, "hi\0", 3) = -1 EBADF (Bad file descriptor) I'm surprised such low level operation doesn't involve syscall? 回答1: Not every call to malloc invokes a syscall. On my linux desktop malloc allocates a space in 128KB blocks

Difference between write() and printf()

落花浮王杯 提交于 2020-01-09 10:37:53
问题 Recently I am studying operating system..I just wanna know: What’s the difference between a system call (like write()) and a standard library function (like printf())? 回答1: A system call is a call to a function that is not part of the application but is inside the kernel. The kernel is a software layer that provides you some basic functionalities to abstract the hardware to you. Roughly, the kernel is something that turns your hardware into software. You always ultimately use write() to write