LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-29-2005, 06:33 AM   #1
babun
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
how can i access /proc with java


how the /proc filesystem can be accessed using java...? please provide code or give some ideas?
 
Old 03-29-2005, 07:22 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,458

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
That would make non portable java code.
Apart that, there is no specific thing I see regarding java use.
Under Linux, most of the /proc pseudo files content is text based, so you can just check the presence, open and read the data as usual.
 
Old 03-29-2005, 09:38 AM   #3
babun
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
hey jlligre , actually currently we r involved in a college project that needs to perform some tweak operation in OS es using java. windows tweaking have been done successfully(by editing the registry) done but in case of linux we cant find any way. can u give us a hint..? neway thanks for ur rep..
 
Old 03-29-2005, 10:03 AM   #4
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
as jlliagre said you may open proc files as text
as for writing/update proc files usually it's done with the echo command
because proc files are kind of virtual file system that doen't really exist
and beware of kcore
i'm still looking for write/update proc file through coding instead of using external command

hopes this help and do help me if you found a way to code write/update
proc files,thanks in advance
 
Old 03-29-2005, 11:32 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,458

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
babun, can you define more precisely what you mean by "some tweak operation in OS es" ?
Java can write to /proc files just as well as echo can do.
 
Old 04-01-2005, 07:32 AM   #6
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
hmm............another runaway....

hi,jlliagre
is there anyway to write to proc files through java or C?

or anybody?

Last edited by alred; 04-01-2005 at 07:37 AM.
 
Old 04-01-2005, 10:11 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,458

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Here's one example in C, of course this could be rewritten in Java too:

Code:
#include <fcntl.h>
main()
{
  int fd;
  int fileMax;
  fd=open("/proc/sys/fs/file-max", O_RDWR,0);
  if(fd!=-1)
  {
    char buf[32];
    read(fd, buf, 32);
    fileMax=atoi(buf);
    if(fileMax>0)
    {
      printf("Current file-max=%d\n", fileMax);
      fileMax+=1024;
      printf("Increasing value to %d\n", fileMax);
      sprintf(buf, "%d\n", fileMax);
      write(fd, buf, strlen(buf));
    }
    else
    {
      printf("Can't read file-max ...\n");
    }
  }
  else
  {
    perror("/proc/sys/fs/file-max");
  }
}
See this page for /proc details:
http://www-106.ibm.com/developerwork...9LinuxOnTheFly
 
Old 04-01-2005, 10:55 AM   #8
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
got it
actually i prefer C because i use pascal and C is easier on pascal
the link is a good read

thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tomcat java.io.FilePermission access denied cherylchase Linux - Software 1 03-21-2006 05:28 AM
Correlation between /proc/devices and /proc/modules ColinLadyka Linux - General 1 02-13-2006 05:25 PM
access to /proc/ioport eddycur Programming 0 11-13-2005 11:28 PM
java /proc (getting system resources) jinics Programming 1 08-26-2004 05:55 AM
Cannot access /proc! man09 Red Hat 4 03-03-2004 09:41 AM


All times are GMT -5. The time now is 06:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration