2

I am tinkering with device driver programming under Ubuntu 14.04.1 LTS and came across a strange behavior; hope you can shed some light on.

sudo insmod hello.ko whom="$" yields the expected output:

Hello $ (0) !!!

but sudo insmod hello.ko whom="$$" yields:

Hello 3275 (0) !!!

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>

MODULE_LICENSE("Dual BSD/GPL");

static char *whom = "world";
static int howMany = 1;

static int __init  hello_init(void){
int i;
for(i = 0; i < howMany; i++){
    printk(KERN_ALERT "Hello %s (%d) !!!\n", whom, i);
    }
return 0;
}

static void __exit hello_exit(void){
printk(KERN_ALERT "Bye bye %s !!!\n", whom);
}

module_init(hello_init);
module_exit(hello_exit);
module_param(howMany, int, S_IRUGO);
module_param(whom, charp, S_IRUGO);
1
  • sudo insmod hello.ko whom="\$" does the job?
    – Jakuje
    Commented Oct 12, 2016 at 20:53

1 Answer 1

3

Nothing to do with the kernel, it's just that $$ expands to the shell's process id, see e.g. Bash's manual.

($$) Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell.

Escape the dollar sign with a backslash, or use single-quotes to prevent the expansion:

$ echo "$$" "\$$" '$$'
29058 $$ $$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .