473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

My native process does not run properly

dmjpro
2,476 2GB
i did run a process throgh java on a server ...........Sun solaris.

how can trap the process information ....
and if the process run for a long time then process terminates in the mean time!

can anyone figure me out why it happens .....................
thanks for ur help
Feb 2 '07 #1
6 2078
horace1
1,510 Expert 1GB
i did run a process throgh java on a server ...........Sun solaris.
how can trap the process information ....
and if the process run for a long time then process terminates in the mean time!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
can anyone figure me out why it happens .....................
thanks for ur helpppppppppppppp
not sure what the exact problem is? did you start the process via Runtime.exec() method and you need to capture the output?
Feb 2 '07 #2
dmjpro
2,476 2GB
thhhannnnnnkkkkkksssssssssss for help
yes u are right ..............
but i want to run a shell scripts on solaris which will backup the database dump .
whenever the process takes long time then it stops automatically....
i don't want to use Process.waitFor() ...without using it i can trap the process information.
how long the process runs in background i don't want it stopped and trap the process information whenever i want.........
plz help me out after see my reply ....
i am online ............
thhhhhhhhhhaaaaaaaaaaaannnnnnnnnnnkkkkkkkkkkksssss ssssssss.........
Feb 3 '07 #3
horace1
1,510 Expert 1GB
thhhannnnnnkkkkkksssssssssss for help
yes u are right ..............
but i want to run a shell scripts on solaris which will backup the database dump .
whenever the process takes long time then it stops automatically....
i don't want to use Process.waitFor() ...without using it i can trap the process information.
how long the process runs in background i don't want it stopped and trap the process information whenever i want.........
plz help me out after see my reply ....
i am online ............
thhhhhhhhhhaaaaaaaaaaaannnnnnnnnnnkkkkkkkkkkksssss ssssssss.........
have a look at this
Expand|Select|Wrap|Line Numbers
  1. // execute a child process using java exec command and get output
  2.  
  3. import java.io.*;
  4. import java.lang.*;
  5.  
  6. public class JavaExec {
  7.  
  8. public static void main (String args[]){
  9.   try {
  10.      // get runtime environment and execute child process
  11.      Runtime systemShell = Runtime.getRuntime();
  12.      Process output = systemShell.exec("ls *.c");
  13.      // open reader to get output from process
  14.      BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
  15.      String line = null;
  16.      System.out.println("<OUTPUT/>");
  17.       while((line = br.readLine()) != null ) 
  18.          { System.out.println(line);  }          // display process output
  19.      System.out.println("</OUTPUT>");
  20.      int exitVal = output.waitFor();             // get process exit value
  21.      System.out.println("Process Exit Value : "+ exitVal);
  22.      }
  23.    catch (IOException ioe){ System.err.println(ioe); }
  24.    catch (Throwable t) { t.printStackTrace();}
  25. }
  26. }
  27.  
it runs ls *.c and gets its output - the br.readLine() returns null when the child terminates
Feb 3 '07 #4
dmjpro
2,476 2GB
i used exactly that code...
but when my child process takes 10 - 15 minutes or more then my code is not working properly and the process terminates before muture death...
using waitFor for shot term process is right but for long term process i think is not right ....
plz help me out.......
thannnkssssss.....................
Feb 3 '07 #5
horace1
1,510 Expert 1GB
i used exactly that code...
but when my child process takes 10 - 15 minutes or more then my code is not working properly and the process terminates before muture death...
using waitFor for shot term process is right but for long term process i think is not right ....
plz help me out.......
thannnkssssss.....................
which process terminates early - the parent or the child?
I have had the following programs running on my machine for over an hour

Expand|Select|Wrap|Line Numbers
  1. // execute a child process using java exec command and get output
  2.  
  3. import java.io.*;
  4. import java.lang.*;
  5.  
  6. public class PassInt {
  7.  
  8. public static void main (String args[]){
  9.   try {
  10.      int a=1;          // value to pass to MyProgram
  11.      // get runtime environment and execute child process
  12.      Runtime systemShell = Runtime.getRuntime();
  13.      Process output = systemShell.exec("java MyProgram " + a);
  14.      // open reader to get output from process
  15.      BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
  16.      String line = null;
  17.      System.out.println("<OUTPUT/>");
  18.       while((line = br.readLine()) != null ) 
  19.          { System.out.println(line);  }          // display process output
  20.      System.out.println("</OUTPUT>");
  21.      int exitVal = output.waitFor();             // get process exit value
  22.      System.out.println("Process Exit Value : "+ exitVal);
  23.      }
  24.    catch (IOException ioe){ System.err.println(ioe); }
  25.    catch (Throwable t) { t.printStackTrace();}
  26. }
  27. }
  28.  
the above program starts the following
Expand|Select|Wrap|Line Numbers
  1. //package shellcommand;
  2. import java.io.*;
  3. import java.lang.*;
  4.  
  5. public class MyProgram {
  6.  
  7. public static void main (String args[]) throws Exception{
  8. System.out.println("Parameter " + args[0]);
  9. for(int i=0;i<100;i++) 
  10.   { Thread.sleep(60000); System.out.println("*" + i); }
  11. }
  12. }
  13.  
which outputs an * every minute
Feb 3 '07 #6
dmjpro
2,476 2GB
my code is something like this .....................
Expand|Select|Wrap|Line Numbers
  1. //MyThread.java
  2. package com.iitkgp.coalnetpim.util;
  3.  
  4. import java.io.*;
  5.  
  6. public class MyThread implements Runnable
  7. {
  8.   private Thread t;
  9.   private String command;
  10.   public Process NATIVE_PROCESS = null;
  11.   public InputStream final_output = null;
  12.   public int exitVal = Integer.MIN_VALUE;
  13.   public String error_string = null; 
  14.   public MyThread(String command)
  15.   {
  16.     this.command = command;
  17.     t = new Thread(this);
  18.     t.start();
  19.   }
  20.   public void run()
  21.   {
  22.     try
  23.     {
  24.       NATIVE_PROCESS = Runtime.getRuntime().exec(command);
  25.       //Thread.sleep(5000); //Keep it slept for 5 seconds so that the browser can get the intial response
  26.       /*exitVal = NATIVE_PROCESS.waitFor();
  27.       if(exitVal == 0) final_output = NATIVE_PROCESS.getInputStream();  //Normal termination
  28.       else final_output = NATIVE_PROCESS.getErrorStream(); //Abnormal termination*/
  29.     }catch(Exception e)
  30.     {
  31.       error_string = e.fillInStackTrace().toString();      
  32.     }
  33.   }
  34.   public boolean isAlive()
  35.   {
  36.     return t.isAlive();
  37.   }  
  38. }
  39.  
Expand|Select|Wrap|Line Numbers
  1. //ThreadTest.jsp
  2.  
  3. <%@ page contentType="text/html;charset=WINDOWS-1252"%>
  4.  
  5. <html>
  6.   <head>
  7.     <title>Simple Thread Test</title>
  8.     <frameset cols = "80%,*">
  9.       <frame src = "ThreadTestMain.jsp">
  10.       <frame src = "ThreadTestHidden.jsp">
  11.     </frameset>
  12.   </head>
  13. </html>
  14.  
  15. //ThreadTestMain.jsp
  16. <%@ page contentType="text/html;charset=WINDOWS-1252"%>
  17.  
  18. <%@ page import = "com.iitkgp.coalnetpim.util.*"%>
  19.  
  20. <html>
  21.   <head>    
  22.   </head>
  23.   <body>
  24.     <%
  25.     try{
  26.       String command = "sh /user6/oracle9iAS/coalnet_screen_backup/backup_from_screen 2 a0d1m4 mms";
  27.       MyThread my_thread = new MyThread(command);
  28.       session.setAttribute("my_thread",my_thread);
  29.     }catch(Exception e)
  30.     {
  31.       request.setAttribute("error_text",e.fillInStackTrace().toString());
  32.     %>
  33.       <jsp:forward page = "../../common/jsp/error_page.jsp" />
  34.     <%
  35.     }
  36.     %>
  37.     <center><h1>Process running started ............</h1></center>
  38.   </body>
  39. </html>
  40.  
  41. //ThreadTestHidden.jsp
  42. <%@ page contentType="text/html;charset=WINDOWS-1252"%>
  43.  
  44. <%@ page import = "com.iitkgp.coalnetpim.util.*"%>
  45. <%@ page import = "java.io.*"%>
  46.  
  47. <html>
  48.   <head>
  49.     <script language = javascript>
  50.       function start_page()
  51.       {
  52.  
  53.         try{
  54.         if(document.all.error_occured)
  55.         {
  56.           window.parent.frames[0].document.body.innerHTML += "<br>" + document.all.error_occured.value;
  57.           window.clearInterval();
  58.           return;
  59.         }
  60.         if(document.all.thread_status.value.toUpperCase() == "FALSE")
  61.         {
  62.           /*if(document.all.exit_value.value == "0")
  63.             window.parent.frames[0].document.body.innerHTML = document.all.output.value;
  64.           else window.parent.frames[0].document.body.innerHTML += "<br><br>" + document.all.output.value;*/
  65.           window.parent.frames[0].document.body.innerHTML += "<br><br><br>Process terminated ...........";
  66.           window.clearInterval();
  67.         }
  68.         else
  69.         {
  70.           //window.parent.frames[0].document.body.innerHTML = document.all.output.value;
  71.           window.parent.frames[0].document.body.innerHTML += "<br>Process still running ...........";
  72.           window.setInterval(reload,2000);
  73.         }
  74.         }catch(err){
  75.           alert(err.description);
  76.           window.clearInterval();
  77.           }        
  78.       }
  79.       function reload()
  80.       {
  81.         window.location.reload();
  82.       }
  83.     </script>
  84.   </head>
  85.   <body onload = start_page()>
  86.   <!--<body>-->
  87.   <%
  88.     boolean thread_status = false;
  89.     MyThread my_thread = null;
  90.     try{
  91.       my_thread = (MyThread)session.getAttribute("my_thread");
  92.       //my_thread.NATIVE_PROCESS.destroy();
  93.       if(my_thread != null){
  94.       thread_status = my_thread.isAlive();
  95.       if(thread_status)
  96.       {
  97.         //BufferedReader output = new BufferedReader(new InputStreamReader(my_thread.NATIVE_PROCESS.getInputStream()));
  98.         StringBuffer string_output = new StringBuffer("");
  99.         //String line;
  100.         /*while((line = output.readLine()) != null)
  101.         {
  102.           string_output.append("<br>");
  103.           string_output.append(line);
  104.         }*/
  105.         //output.close();
  106.         %>
  107.           <input type = hidden name = output value = "<%=string_output.toString()%>">
  108.         <%
  109.       }
  110.       else
  111.       {
  112.         //BufferedReader output = new BufferedReader(new InputStreamReader(my_thread.final_output));
  113.         StringBuffer string_output = new StringBuffer("");
  114.         //String line;
  115.         /*while((line = output.readLine()) != null)
  116.         {
  117.           string_output.append("<br>");
  118.           string_output.append(line);
  119.         }*/
  120.         %>
  121.           <input type = hidden name = exit_value value = "<%=my_thread.exitVal%>">
  122.           <input type = hidden name = output value = "<%=string_output.toString()%>">
  123.         <%
  124.         //output.close();
  125.         session.removeAttribute("my_thread");
  126.       }
  127.      }
  128.      else{%>
  129.       <input type = hidden name = error_occured value = "An internal error occured">
  130.      <%}
  131.     }catch(Exception e)
  132.     {
  133.     %>
  134.       <input type = hidden name = error_occured value = "<%="Debasis" + e.fillInStackTrace().toString()%>">
  135.     <%
  136.     }
  137.     %>
  138.     <input type = hidden name = thread_status value = "<%=thread_status%>">
  139.     <%if(my_thread.error_string != null){%>
  140.       <input type = hidden name = error_occured value = "<%="Moumita" + my_thread.error_string%>">
  141.     <%}
  142.     %>
  143.     <input>
  144.   </body>
  145. </html>
  146.  
At first the link called the TestThread.jsp...
The comment line i first tried to execute but the expected output i didn't get......
the ThreadTest.jsp starts the thread and will show the current process status
the ThreadTestHidden.jsp will looks after the process by sending request in every two minutes.
and the command run on the solaris is ....
sh /user6/oracle9iAS/coalnet_screen_backup/backup_from_screen 2 a0d1m4 mms
2 is for module choice
and mms for module name
the module contains thousands of tables and other objects such as procedures....etc...etc.......
the scripts are ...........

Expand|Select|Wrap|Line Numbers
  1. //backup_from_screen
  2. choice=$1
  3. case $choice in
  4.         1) adm_password=$2
  5.            sh /user6/oracle9iAS/coalnet_screen_backup/all_backup_db $adm_password ;;
  6.         2) module_codes=$3
  7.            adm_password=$2
  8.            sh /user6/oracle9iAS/coalnet_screen_backup/module_backup_db $module_codes $adm_password ;; 
  9.  
  10.         3) module_codes=$3
  11.            adm_password=$2
  12.            table_names=$4
  13.            sh /user6/oracle9iAS/coalnet_screen_backup/module_backup_tables $module_codes $adm_password $table_names ;;
  14.         4) sh /user6/oracle9iAS/coalnet_screen_backup/application_complete ;;
  15.     5) module_codes=$2
  16.        sh /user6/oracle9iAS/coalnet_screen_backup/application_module $module_codes ;;
  17. esac
  18. echo "Backup Done"
  19.  
plz help me out after see my reply......................

thhhhhhhhhhhannnnnnnnnnnnnnnnnnkkkkkkkkkkkkkkkksss ssssss.................
Feb 3 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dan | last post by:
Hi Gurus I got a very basic question to ask: When a .NET exe (MSIL) is first run, the JIT-compiler will converts the IL into native codes so that it can executes on the current machine. my...
7
by: Daniel Dünker | last post by:
Hello. I was screwing around a bit with the exe-files produced by .Net Compilers and trying to understand how they work... so i ended up at the 6 Byte stub, which calls the _CorExeMain in...
5
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and...
2
by: Dilip7597 | last post by:
Hello Guys, while checking one of the program, I found one difficulty with my program. there was a condition like (!!a), and I don't know what does it means. So if anybody knows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.