proc

/proc/[pid]/cmdline file size

时光怂恿深爱的人放手 提交于 2019-12-01 12:20:21
问题 i'm trying to get the filesize of the cmdline file in proc/[pid]. For example porc/1/cmdline. The file is not empty, it contains "/sbin/init". But i get file_size = 0. int main(int argc, char **argv) { int file_size; FILE *file_cmd; file_cmd = fopen("/proc/1/cmdline", "r"); if(file_cmd == NULL) { perror("proc/1/cmdline"); exit(1); }else { if(fseek(file_cmd, 0L, SEEK_END)!=0) { perror("proc/1/cmdline"); exit(1); } file_size = ftell(file_cmd); } printf("fs: %d\n",file_size); fclose(file_cmd); }

How do I find the inode of a TCP socket?

寵の児 提交于 2019-12-01 06:32:57
How do I tie values in the 'inode' column of /proc/net/tcp to files in /proc/<pid>/fd/ ? I was under the impression that the inode column in the TCP had a decimal representation of the socket's inode, but that doesn't seem to be the case. For example, if I run telnet localhost 80 , I see the following (telnet is pid 9021). /proc/net/tcp contains sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 23: 0100007F:CE2A 0100007F:0050 01 00000000:00000000 00:00000000 00000000 1000 0 361556 1 00000000 20 0 0 10 -1 which makes me think that the inode of the socket

Purpose of & (ampersand) in Ruby for procs and calling methods

断了今生、忘了曾经 提交于 2019-11-30 12:49:44
问题 I've noticed that a lot of examples dealing with Ruby Procs have the following & symbol in it. # Ruby Example shout = Proc.new { puts 'Yolo!' } def shout_n_times(n, &callback) n.times do callback.call end end shout_n_times(3, &shout) # prints 'Yolo!' 3 times My question is what is the functional purpose behind the & symbol? It seems that if I wrote the same exact code without &, it works as expected: # Same code as previous without & shout = Proc.new { puts 'Yolo!' } def shout_n_times(n,

Purpose of & (ampersand) in Ruby for procs and calling methods

痴心易碎 提交于 2019-11-30 03:43:41
I've noticed that a lot of examples dealing with Ruby Procs have the following & symbol in it. # Ruby Example shout = Proc.new { puts 'Yolo!' } def shout_n_times(n, &callback) n.times do callback.call end end shout_n_times(3, &shout) # prints 'Yolo!' 3 times My question is what is the functional purpose behind the & symbol? It seems that if I wrote the same exact code without &, it works as expected: # Same code as previous without & shout = Proc.new { puts 'Yolo!' } def shout_n_times(n, callback) n.times do callback.call end end shout_n_times(3, shout) # prints 'Yolo!' 3 times This article

Is there a more concise way to call an outside method on a map in Ruby? [duplicate]

瘦欲@ 提交于 2019-11-29 22:56:42
问题 This question already has answers here : How to turn a Ruby method into a block? (3 answers) Closed 5 years ago . Is there a more concise way of doing this? # Given a directory containing subdirectories: foo, bar targets = ['./foo', './bar', './free'] targets.map{ |d| Dir.exists? d } # => [ true, true, false ] I'd love to be able to do something similar to proc calls... it feels cleaner: # targets.map( Dir.exists? ) 回答1: Yes, possible this way, but not good for performance (see post: Is the

What is the &: of &:aFunction doing? [duplicate]

删除回忆录丶 提交于 2019-11-29 18:17:29
This question already has an answer here: What does map(&:name) mean in Ruby? 15 answers I'm reviewing someone's ruby code and in it they've written something similar to: class Example attr_reader :val def initialize(val) @val = val end end def trigger puts self.val end anArray = [Example.new(10), Example.new(21)] anArray.each(&:trigger) The :trigger means the symbol is taken and the & transforms it into a proc ? If that's correct, is there any way of passing variables into trigger apart from using self. ? This is related but never answered: http://www.ruby-forum.com/topic/198284#863450 is

Chaining & to_proc on symbol

无人久伴 提交于 2019-11-29 07:10:27
It's well known to Rubyist & will call to_proc on a symbol, so [:a, :b, :c].map(&:to_s) is equivalent to [:a, :b, :c].map { |e| e.to_s } # => ["a", "b", "c"] Say I want to call another method right after to_s , these two implementations will work: [:a, :b, :c].map { |e| e.to_s.upcase } [:a, :b, :c].map(&:to_s).map(&:upcase) My question is, is there a way to chain the & Symbol#to_proc call in one parameter? Something like: [:a, :b, :c].map(&:to_s:upcase) Thanks! If you're only doing: %i[a b c].map { |e| e.to_s.upcase } then just use the block and get on with more important things. If you're

What is the &: of &:aFunction doing? [duplicate]

别来无恙 提交于 2019-11-28 14:05:59
问题 This question already has an answer here: What does map(&:name) mean in Ruby? 15 answers I'm reviewing someone's ruby code and in it they've written something similar to: class Example attr_reader :val def initialize(val) @val = val end end def trigger puts self.val end anArray = [Example.new(10), Example.new(21)] anArray.each(&:trigger) The :trigger means the symbol is taken and the & transforms it into a proc ? If that's correct, is there any way of passing variables into trigger apart from

/proc kcore file is huge

你说的曾经没有我的故事 提交于 2019-11-28 07:13:30
After experiencing a DDOS attack, somehow /proc/kcore is very huge, I use a small php class to check the current disk space, and how many has been used. It shows the following: Total Disk Space: 39.2 GB Used Disk Space: 98 GB Free Disk Space: 811.6 MB My question is, is it safe to delete the /proc/kcore file? Or is there a solution on getting it to an normal size. The filesize of /proc/kcore is 140.737.486.266.368 bytes I have hosted my server at DigitalOcean. If any more information needed to know, please ask ;) Many thanks! Edit... df -h returns: Filesystem Size Used Avail Use% Mounted on

/proc kcore file is huge

送分小仙女□ 提交于 2019-11-26 20:23:48
问题 After experiencing a DDOS attack, somehow /proc/kcore is very huge, I use a small php class to check the current disk space, and how many has been used. It shows the following: Total Disk Space: 39.2 GB Used Disk Space: 98 GB Free Disk Space: 811.6 MB My question is, is it safe to delete the /proc/kcore file? Or is there a solution on getting it to an normal size. The filesize of /proc/kcore is 140.737.486.266.368 bytes I have hosted my server at DigitalOcean. If any more information needed