Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
RMotta2408
Creator II
Creator II

Getting the PID (the same captured by tLogCatcher)

Hello everyone,

 

I'm trying to get the PID value (the same it is shown in tLogCatcher) but I can't get the same one.
Let me explain: I'm using the following instruction to get the Process name, which includes its PID:

java.lang.management.ManagementFactory.getRuntimeMXBean().getName()

This will get me "11876@DESKTOP-LI4JPMJ"

To get the PID I'm doing as follows:

java.lang.management.ManagementFactory.getRuntimeMXBean().getName().substring(0, java.lang.management.ManagementFactory.getRuntimeMXBean().getName().indexOf("@"));

This will get me "11876"

But, in the same Job, the component tLogCatcher displays the following information:

+------------+-------------------------------+
| key        | value                         |
+------------+-------------------------------+
| moment     | 2024-05-30 20:23:54           |
| pid        | yb9Lyl                        |
| root_pid   | yb9Lyl                        |
| father_pid | yb9Lyl                        |
| context    | Default                       |
| priority   | 6                             |
| type       | Java Exception                |
| origin     | tFileOutputExcel_1            |
| message    | java.io.FileNotFoundException:|
| code       | 1                             |

As you can see, these are not the same values.
Can anyone please let me know how to get the PID shown by the tLogCatcher component?

Thank you so much,
Rui

 

Labels (2)
1 Solution

Accepted Solutions
janterje
Partner - Contributor III
Partner - Contributor III

Hi,

If you want to retrieve the PID of a job inside a job, it is luckily very easy.

You just use pid as the value in any component.

pid.png

 

And voila:
.------.
|tLogRow_1|
|=----=|
|pid |
|=----=|
|gq3o5u|
'------'

 

View solution in original post

8 Replies
Shicong_Hong
Support
Support

Hello 

Open the Code tab to view the Java code generated by the Job. These lines of Java code generate a PID string with 6 length.

	if (pid == null || "0".equals(pid)) {
			pid = TalendString.getAsciiRandomString(6);
		}

 

Regards

Shicong

 

RMotta2408
Creator II
Creator II
Author

Hi @Shicong_Hong ,

 

Thank you for replying.
I may have not made myself clear. I need to get the PID value while running the Job.

Thank you,

Rui

Shicong_Hong
Support
Support

You can use tStatCatcher component to capture the job statistics information which includes the PID value, but if you want to customize the code to generate PID, it cannot be the same as the PID generated by the job, the job use function TalendString.getAsciiRandomString(6) to generates a random string with 6 length.

RMotta2408
Creator II
Creator II
Author

Good morning @Shicong_Hong ,

My wish is not to generate a PID code. But, instead, capture it to insert on a DB along with the records received by an API.
That's the challenge. To call an API, receive the results and insert them in a table along with the PID.

Thank you,
Rui

janterje
Partner - Contributor III
Partner - Contributor III

Hi,

If you want to retrieve the PID of a job inside a job, it is luckily very easy.

You just use pid as the value in any component.

pid.png

 

And voila:
.------.
|tLogRow_1|
|=----=|
|pid |
|=----=|
|gq3o5u|
'------'

 

Shicong_Hong
Support
Support

Link the result of API to a tMap and add extra job information in the output table, such as pid, jobName, projectName etc as you want. As Janterje said, to get the value of these job information, you can directly use the variable name in the expression field.

pid for PID

jobName for Job Name

projectName for Project Name

 

RMotta2408
Creator II
Creator II
Author

Really?!??!?!

Wow, thankyou so much. I really appreciate your help.

Cheers,

Rui

RMotta2408
Creator II
Creator II
Author

Thank you.
I will do that.

Thank you so much for the help.

 

Rui