Convert a local channel into a shared global channel.


share( channel , name )





process I/O channel number that was returned when the channel was opened using the fopen() or popen() function


character string used to identify the shared channel in the table of global channels BMC Software recommends that you specify a nonnumeric name to avoid conflicts with numbers used internally for local channels. Using a number for name does not actually cause the share() function to fail but will raise a PSL run-time warning. The share() function will dutifully place the specified numeric name in the global table, leading to potential conflicts with local channels in close(), read(), write(), and readln() functions.


The share() function is the main function for using shared channels. The share() function propagates an existing localchannel into the table of global channels as name. Channels opened by either the popen() or fopen() functions can be shared. 

If the share() function is successful, it returns 0. The local channel is no longer available in the process that opened it and does not require a close() function. In fact, the close() function will return an error since it will not find the local channel. 

The share() function will fail, returning -1 and setting the PSL errno variable under the following conditions:

  • local channel does not exist
  • global channel name already exists in the global channel table

Upon failure, the local channel is unchanged and still available. No global channel is added. 

A global channel is referred to by name when passed to the read(), readln(), write(), and close() functions. These functions will first search the local channel table containing only channel numbers and then the global channel table.

The share() function and the Knowledge Module Developer

The PATROL Agent performs no explicit cleanup of the shared channels. It is up to the Knowledge Module developer to clean up as well as possible. Unfortunately, there is no easy way to intercept a console request to deactivate an application or parameter and hence doing so for an application using shared channels will most likely not terminate the external process. 

For a brute-force cleanup, it is possible to use close( name,3) to remove a global channel and terminate its external process. It is also possible to write a "cleanup all shared channels" menu command using the get_chan_info() function to return a list of shared channels and close() to remove them.


The following PSL script uses t he share() func tion to convert a local channel into a shared global channel:

chan = fopen("/etc/passwd"."r");
# read from the global channel
while ((user = readln("passwd_handle")) != EOF)
Was this page helpful? Yes No Submitting... Thank you