473,804 Members | 3,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

My native process does not run properly

dmjpro
2,476 Top Contributor
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 2097
horace1
1,510 Recognized Expert Top Contributor
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 helpppppppppppp pp
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 Top Contributor
thhhannnnnnkkkk kksssssssssss 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 ............
thhhhhhhhhhaaaa aaaaaaaannnnnnn nnnnkkkkkkkkkkk sssssssssssss.. .......
Feb 3 '07 #3
horace1
1,510 Recognized Expert Top Contributor
thhhannnnnnkkkk kksssssssssss 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 ............
thhhhhhhhhhaaaa aaaaaaaannnnnnn nnnnkkkkkkkkkkk sssssssssssss.. .......
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 Top Contributor
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 Recognized Expert Top Contributor
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 Top Contributor
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 ThreadTestHidde n.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_scr een 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....e tc...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.......... ............

thhhhhhhhhhhann nnnnnnnnnnnnnnn nkkkkkkkkkkkkkk kksssssssss.... .............
Feb 3 '07 #7

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

Similar topics

5
5316
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 question is: 1) where does the native codes reside? is it saved somewhere in the hard drive or it will only resides in the memory? or does the JIT compiler writes
7
1529
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 mscoree.dll ... so i thought "Hey, thats how it tells the Framework, that it shall load it as .Net programm...". So i build some native code into it which should have been executed before the .Net programm itself gets loaded. Trying that on a...
5
5238
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 marshaling the struct to be able to use it in sendmessage... Here is an example LM_GETITEM: http://msdn.microsoft.com/en-us/library/bb760720(VS.85).aspx
2
10487
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 about it then please help me out. Thanks, Dilip
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.