Find the answer to your Linux question:
Results 1 to 7 of 7
Hi all, I've been trying to simply use printk for a while now as I'm doing a little kernel modding, however, things aren't going as smoothly as I would've wished. ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    7

    Printk defined loglevels not found

    Hi all,

    I've been trying to simply use printk for a while now as I'm doing a little kernel
    modding, however, things aren't going as smoothly as I would've wished.

    Here's the very simple code:

    Code:
    #include <linux/kernel.h>
    
    int main()
       {
       printk(KERN_DEBUG "This is a test\n");
    
       return 0;
       }
    For whatever reason, it can't find the definition for "KERN_DEBUG" (or any
    defined log level for that matter) even though I can clearly see them DEFINE-d
    in /usr/src/kernel/linux-2.26.8-57/include/linux/kernel.h .

    I'm at a loss as to what is causing this.
    Any ideas would be most appreciated.

    Thank you,
    -Elleroth

    (Oh and this was my first post ever on the Linux Forums! Yay me)

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    I believe printk can only be used in kernel modules not user processes..

    This guide should start in the right direction...

    The Linux Kernel Module Programming Guide
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    7
    Excellent.

    Looks like it compiled okay after embedding it into kernel/sched.c so I'm going to assume that you're correct.

    Thanks,
    -Elleroth

  4. #4
    Just Joined!
    Join Date
    Feb 2010
    Posts
    7
    Well it seems to be in the kernel, but it doesn't want to print.

    The message is nowhere within /var/log/ and I can't get it to print to any log or the
    terminal. (I even tried fiddling with /proc/sys/kernel/printk but that didn't seem to
    help.)

    Everything compiled beautifully; What could have gone wrong?

    -Elleroth

  5. #5
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You'll have to post some code for any reasonable answers...
    Make mine Arch Linux

  6. #6
    Just Joined!
    Join Date
    Feb 2010
    Posts
    7
    Sorry... I assumed that since it compiled properly, it wouldn't be necessary.

    Here's the code (modified sched_rt.c; lines 1767 - 1789):
    Code:
    /* 
     * Function: getTimesliceRatio
     * 
      * Returns the number of processes that are siblings of the 
     *  process defined by the task_struct passed-in.
     */
    int getTimeSliceRatio(struct task_struct *ts)
    	{
    	//Get the sibling list head
    	int timeslice_ratio = 1;
    	struct list_head head_struct = ts->sibling;
    	struct list_head *head = head_struct.next;
    	while(head != NULL)
    		{
    		if(head->next != NULL)	//...and if next node is NOT NULL
    			{
    			head = head->next;
    			timeslice_ratio++;
    			}
    		else			//...Otherwise the list is exhausted
    			{ }
    		}
    
    	printk(KERN_DEBUG "Number of siblings for process %d is: %d\n",
    				ts->pid, timeslice_ratio);
    	
    	//Return the number of siblings that this process has
    	return timeslice_ratio;
    	}
    Seems like it should work, but I'm getting no messages sent anywhere.

    Thanks for all your speedy replies,
    -John

  7. #7
    Just Joined!
    Join Date
    Feb 2010
    Posts
    7
    I've just been informed that I cannot use these forums for aid on school assignments. Please close this thread (everything is working now anyway).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...