Skip to content

Searching and selecting strings from a file

I have a trouble in separating few exact ‘fields’ with strings and then putting them into .txt file. I need to extract ‘nologin’ users from /etc/passwd file and that is an easy step. I’m using this command: cat command gives me for example: and it is saved to file1.txt Now I have…

Buggy simple function for binary search (C++)

I wrote a simple function for binary search, but it’s not working as expected. I have a vector with 4000000 32-bit ints. Usually, when I search for a number, if it’s there, it’s found and the index is returned, if it’s not, -1 is returned (the index always corresponds to the value, but…

How to properly print file content to the command line in C?

I want to print the contents of a .txt file to the command line like this: The file testfile.txt looks like this: The function prints only the first 4 letters line. When using sizeof instead of strlen the whole file is printed. Why is strlen not working? Answer When using sizeof instead of strlen the whole fi…

Managing Log File Sizes

I am implementing a simple log file handler for an embedded device. I cannot use syslog because it is already reserved for other uses. The device’s SSD size is limited, so there is a real risk of the log file using all of the disk space, which will crash the device. What is the cheapest way I can guaran…

Linux top output unrealistic?

I’m having a weird issue with a java process which is consuming a lot of resources on a linux VM. The output of top for the process is the below : So this shows that the process is actually consuming 21G of physical memory ? When checking the process in more detail I can see it was started with -Xmx4G