proc

how to send the kernel data to the user the space using procfs?

▼魔方 西西 提交于 2019-12-25 16:44:42
问题 I am calculating a timestamp in the kernel and later I want to tranfer the tmestamp from kernel to the user space. So I am using procfs for communication between kernel and user. I am using the procfile_read function for sending the data from kernel as shown below. I modified and calculated the timestamp of the kernel code as shown below. //this code is at network device driver level. int netif_rx(struct sk_buff *skb) { __net_timestamp(skb);//I modify the code in kernel to get the timestamp

Best way to test named scopes in Rails4

风格不统一 提交于 2019-12-25 02:40:58
问题 As a part of the migration from Rails 3.2 to Rails 4, all named scopes need a proc block. Read more here: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#active-record I had missed updating a scope in one of my models, which ended up biting me in production after my migration. So I wanted to figure out how to test this issue, and I found some strange behavior. In some cases the scopes appear to work fine without the proc, but not in other cases. # models/offer.rb class Offer <

Using Proc with ruby hash merge results in

浪尽此生 提交于 2019-12-24 16:20:03
问题 I'm trying to DRY up my code by using Procs. I have many lines that look like this (other lines may have fees, discounts, taxes, rather than revenue): h.merge!({revenue: 500}){|key, old_val, new_val| old_val + new_val} I tried to write a Proc that looks like this: hproc = Proc.new {|key, old_val, new_val| old_val + new_val} And simplify the first line by doing this: h.merge!({revenue: 500})(&hproc) However, I get the error: syntax error, unexpected '(', expecting end-of-input h.merge!(

Why I can't read /proc/net/xt_qtaguid/stats correctly by FileReader in Android ICS

对着背影说爱祢 提交于 2019-12-24 02:23:30
问题 I want to read /proc/net/xt_qtaguid/stats in Android ICS, which records all interfaces and applications traffic stats. following is the code snippet: String line = null; BufferReader reader = new BufferedReader(new FileReader(new File("/proc/net/xt_qtaguid/stats"))); line = reader.readLine();/*Here I can read the 1st line correctly, it return "idx iface acct_tag_hex..."*/ splitLine(line, keys); line = reader.readLine();//!!!!!Read next line, it returns null!!!!!! If I cat this file, it will

Reference the invoking object in the passed block in Ruby

為{幸葍}努か 提交于 2019-12-22 10:54:34
问题 Is there any way to get hold of the invoked object inside the block thats being called. For instance, is there any way for the blocks to get access to the scope of the method batman or the class SuperHeros class SuperHeros attr_accessor :news def initialize @news = [] end def batman task puts "Batman: #{task} - done" yield "feed cat" @news << task end end cat_woman = lambda do |task| puts "Cat Woman: #{task} - done" # invoker.news << task end robin = lambda do |task| puts "Robin: #{task} -

Where m flag and o flag will be stored in Linux

三世轮回 提交于 2019-12-22 04:37:22
问题 I want to know the value of m flag and o flag of recently received Router Advertisement. From the kernel source code I came to know that m flag and o flag are stored. /* * Remember the managed/otherconf flags from most recently * received RA message (RFC 2462) -- yoshfuji */ in6_dev->if_flags = (in6_dev->if_flags & ~(IF_RA_MANAGED | IF_RA_OTHERCONF)) | (ra_msg->icmph.icmp6_addrconf_managed ? IF_RA_MANAGED : 0) | (ra_msg->icmph.icmp6_addrconf_other ? IF_RA_OTHERCONF : 0); . . . Then I believe

Linux file deleted recovery

穿精又带淫゛_ 提交于 2019-12-21 04:36:13
问题 Is there a way to create a file in Linux that link to a specific iNode? Take this scenario: There is a file that is in course of writing (a log maybe) and the specific file is deleted but a link in the dir /proc is still pointing at it. In this case we need not a bare copy of it but an hard link to it so we can have the future modifications and the most last modification before the process close and the system delete it. If we have the iNode number is there a way to achieve this goal? 回答1:

ruby中Block, Proc 和 Lambda 的区别

谁都会走 提交于 2019-12-20 19:42:58
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Block 与Proc的区别: Block是代码块,Proc是对象; 参数列表中最多只能有一个Block, 但是可以有多个Proc或Lambda; Block可以看成是Proc的一个类实例. Proc 与Lambda 区别: Proc和Lambda都是Proc对象; Lambda检查参数个数,当传递的参数超过一个时,会报错,而Proc不检查,当传递参数多于一个时, 只传递第一个参数, 忽略掉其他参数; Proc和Lambda中return关键字的行为是不同的. # Block Examples [ 1 , 2 , 3 ]. each { | x | puts x * 2 } # block is in between the curly braces [ 1 , 2 , 3 ]. each do | x | puts x * 2 # block is everything between the do and end end # Proc Examples p = Proc . new { | x | puts x * 2 } [ 1 , 2 , 3 ]. each ( & p ) # The '&' tells ruby to turn the proc into a block proc = Proc .

浅谈Ruby中的block, proc, lambda, method object的区别

江枫思渺然 提交于 2019-12-20 19:27:53
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前言 当大家在百度中搜索“block proc lambda”的时候,会出来很多关于这几个概念之间区别的介绍,既然搜索结果中已经有了这些介绍,那为什么还要写这篇文章? 相信看过百度搜索结果中排名靠前的几篇文章的同学,都会发现其实这些文章并没有很好的说明他们之间区别是什么,大多只是介绍各自的用法,加上些许的区别,即使个别介绍了一些区别,也不够系统,不够深入。 正是基于上述原因,才酝酿了本文。本文以简单示例的方式,详细的介绍了它们之间的区别。相信您阅读完本文,一定会豁然开朗,并在今后的开发中准确并优雅的使用它们。 由于时间,个人能力水平等有限,本文难免有错误或缺失之处,欢迎不吝指出。 block & proc 在介绍它们的区别之前,我们先来看一段有关block的简单使用方法: def use_yield yield end use_yield do puts 'use yield' end def use_block_call(&block) block.call end use_block do puts 'use block call' end 以上介绍了两种在函数中使用block的方式,第一种是通过yield来使用block,另外一种则是通过block.call来使用block。

How do I find the inode of a TCP socket?

北战南征 提交于 2019-12-19 08:59:58
问题 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