Progress 4gl - UNIX process manipulation with output-through
The attached file - osfunctions.i shows how the progress input-output through statement can be used to manipulate UNIX processes.
The attached demo program “dontrunthis.p” will kill ALL shells of the logged in UNIX user, including your own, when you run it in a progress editor. When run in the webspeed scripting lab, it will kill all UNIX shells of the webspeed UNIX User ID.
Warning : If your colegues are logged in with the same UNIX User ID when you run the demo program, their shells will be killed as well - they may loose data.
/*********************************
file1 - dontrunthis.p
*********************************/
{osfunctions.i}
killUnixProcess(getUnixProcessId(getUnixUser(), "sh")).
/*********************************
file2 - osfunctions.i
*********************************/
/* osfunctions.i
|^^^/|
| @ @| Auth: [Jeevan@Alterlife.org]
| | Tstp: Jan 11th, 2006.
/`
|.. |
| . ` | Desc:
|/ . | Functions for Unix Process Manipulation.
| ` ` |
`._`__.'
==="="===
Functions:
getUnixUser() -
returns the UNIX user ID of the logged in
user.
getUnixProcessId(user_id, processName) -
returns a comma separated list of UNIX process IDs
*/
/* &scoped-define debug_mode true. */
def stream osBuffer.
function getUnixUser returns char:
def var user_id as char no-undo.
input stream osBuffer through "echo $USER".
import stream osBuffer user_id.
input stream osBuffer Close.
return user_id.
end.
function getUnixProcessId returns char(
user_id as char,
processName as char
):
def var processList as char init "" no-undo.
def var line as char.
input stream osBuffer through
value("ps -u " + user_id + " | grep -i " + processName).
repeat:
import stream osBuffer unformatted line.
processList = processList + substr(line, 1, 10) + ",".
end.
if processList <> “” then
processList = substr(processList, 1, length(processList) - 1).
input stream osBuffer Close.
return processList.
end.
function killUnixProcess returns char(
processList as char
):
def var i as int.
def var line as char.
def var commandOutput as char.
do i = 1 to num-entries(processList):
input stream osBuffer through
value(”kill -9 ” + entry(i, processList)).
repeat:
import line.
commandOutput = commandOutput + line + “n”.
end.
input stream osBuffer Close.
end.
return commandOutput.
end.
function isProcessAlive returns logical(
processId as char
) :
def var i as int.
def var line as char.
input stream osBuffer through
value(”ps ” + processId).
repeat:
import stream osBuffer line.
i = i + 1.
if i > 1 then return true.
end.
input stream osBuffer close.
return false.
end.